From patchwork Mon Jul 16 15:25:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10013 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id EF06523E2F for ; Mon, 16 Jul 2012 15:26:06 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9C577A188C4 for ; Mon, 16 Jul 2012 15:26:06 +0000 (UTC) Received: by yenq6 with SMTP id q6so5511849yen.11 for ; Mon, 16 Jul 2012 08:26:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=yLmNba/2YCmsxL2RwVCutYqpGF+vgr/Gnycyq0Lmzjw=; b=UAGpQUCg/H7c50JmjghZ5x/AJpFe6cWpTzKMXit2qkKkE1RvWkipLI1msepoDamEoJ Emv+O5Zo7RL38z9uJGfVLWcZc5a4n+pCO+lcxJbWVBY3zq4wX50H/q7Yp2l6oWxaknqX rUFTRNtqEMFaQMYhsz4Q6ctphXacCksGNcZ5FKGJURCLmsfWKMMTeB6EFw/EdL12Rodw n7WkeBEb2B5HITwQmaWbDbJOfXkYwXuQVAPrOIcpzFKJIW2ucwmgf95RfwVQAvXf+8Ji QwrZaVoapk6jJdAZ7PnXo/SGiBvJTGieoICqEhFfM4F/wYeZ0Jh0NcOqK6q/O2vbwZzn W+gQ== Received: by 10.42.68.65 with SMTP id w1mr6022866ici.57.1342452365952; Mon, 16 Jul 2012 08:26:05 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.241.2 with SMTP id lc2csp9635ibb; Mon, 16 Jul 2012 08:26:04 -0700 (PDT) Received: by 10.216.50.200 with SMTP id z50mr5965232web.104.1342452363592; Mon, 16 Jul 2012 08:26:03 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id o11si20939735wel.146.2012.07.16.08.26.02 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 08:26:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SqnBL-0002R6-Hf; Mon, 16 Jul 2012 16:25:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [PATCH v2] qerror: Add QERR_PROPERTY_SET_AFTER_REALIZE Date: Mon, 16 Jul 2012 16:25:55 +0100 Message-Id: <1342452355-9341-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQmH2U0pUXeTXCBRkdubeWjr4LYmpgXA1Riu30AHHdxN5EkW0up/4Tl+e67LAfGRoZ9e4mNg Add a new QError QERR_PROPERTY_SET_AFTER_REALIZE for attempts to set a QOM or qdev property after the object/device has been realized. This allows a slightly more informative diagnostic than the previous "permission denied" message. Signed-off-by: Peter Maydell --- Changes since the v1 (which was sent way back in March...): * rebased on master now a pile of qdev/qom changesd have landed * fixed some overlong lines * avoid gcc '?:' extension * a couple of set_ functions in qdev-properties.c are new since v1 and needed their QERR_PERMISSION_DENIED checks changing hw/qdev-properties.c | 42 ++++++++++++++++++++++++++++-------------- qerror.c | 5 +++++ qerror.h | 3 +++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 0b89462..ae0c7a7 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -54,7 +54,8 @@ static void set_bit(Object *obj, Visitor *v, void *opaque, bool value; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -94,7 +95,8 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque, uint8_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -161,7 +163,8 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque, uint16_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -194,7 +197,8 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque, uint32_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -219,7 +223,8 @@ static void set_int32(Object *obj, Visitor *v, void *opaque, int32_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -292,7 +297,8 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque, uint64_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -380,7 +386,8 @@ static void set_string(Object *obj, Visitor *v, void *opaque, char *str; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -458,7 +465,8 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, int ret; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -627,7 +635,8 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, VLANState *vlan; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -697,7 +706,8 @@ static void set_mac(Object *obj, Visitor *v, void *opaque, char *str, *p; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -767,7 +777,8 @@ static void set_enum(Object *obj, Visitor *v, void *opaque, int *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -798,7 +809,8 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, char *str; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -868,7 +880,8 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque, const int64_t max = 32768; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } @@ -936,7 +949,8 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, unsigned int slot = 0, func = 0; if (dev->state != DEV_STATE_CREATED) { - error_set(errp, QERR_PERMISSION_DENIED); + error_set(errp, QERR_PROPERTY_SET_AFTER_REALIZE, + dev->id ? dev->id : "", name); return; } diff --git a/qerror.c b/qerror.c index 92c4eff..2af081d 100644 --- a/qerror.c +++ b/qerror.c @@ -233,6 +233,11 @@ static const QErrorStringTable qerror_table[] = { .desc = "Property '%(device).%(property)' not found", }, { + .error_fmt = QERR_PROPERTY_SET_AFTER_REALIZE, + .desc = "Property '%(device).%(property)' " + "cannot be set after realize", + }, + { .error_fmt = QERR_PROPERTY_VALUE_BAD, .desc = "Property '%(device).%(property)' doesn't take value '%(value)'", }, diff --git a/qerror.h b/qerror.h index b4c8758..b5cb730 100644 --- a/qerror.h +++ b/qerror.h @@ -196,6 +196,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_PROPERTY_NOT_FOUND \ "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }" +#define QERR_PROPERTY_SET_AFTER_REALIZE \ + "{ 'class': 'PropertySetAfterRealize', 'data': { 'device': %s, 'property': %s } }" + #define QERR_PROPERTY_VALUE_BAD \ "{ 'class': 'PropertyValueBad', 'data': { 'device': %s, 'property': %s, 'value': %s } }"