From patchwork Fri Apr 14 16:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 673134 Delivered-To: patch@linaro.org Received: by 2002:adf:fcce:0:0:0:0:0 with SMTP id f14csp262497wrs; Fri, 14 Apr 2023 09:05:54 -0700 (PDT) X-Google-Smtp-Source: AKy350ZH3zsu3GH/wvZqbFx6KV6SUicEHuhMxYL0mbbHlC6G/pdcOlOEiBGWp1udSYNKVVlKmK7W X-Received: by 2002:a05:622a:1a1a:b0:3bd:140c:91ed with SMTP id f26-20020a05622a1a1a00b003bd140c91edmr9521614qtb.52.1681488354198; Fri, 14 Apr 2023 09:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681488354; cv=none; d=google.com; s=arc-20160816; b=c3XKpzhTXiXO3mSPyLC1lTyfohvCw+fS0QMkUrT2jrbVajS0QK6yH2tpwW4yRGCu/2 4pzZLyWPptQ479CtsUsDT+oWoLG8XExWtMcj4tLW0DXNKwdUhNoLy4lptdX28WRIk/Gc 68iTtquzUgNb90IJA8Hh/g95qGvQVezv1u+8ODl5AQqiTxqr61OtXZN8Wz2bq9zuOYuQ sWDEyzVwM07EAVHtNjeJC4p8vmwYJkOnVDmv/szhXd9Xw1ksCzV62u8c+Bvod8opusKO DYGjuxO3lJE0Ew7snqMH53zpYcGdVh5U7dK+uneqBCAIk0I8JGj93aahgZ7nY6LGmzAr Bb/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=87Eys71a5bFDwpsmcqiXjalsGOMTQZkXpUaxljHCLjI=; b=ji3QMuJ/LJ7RbGmKIf/dKmsHDEYzZDEHjfV2++2IK73PYKERhWTbxXQGA6Qfyho0y+ 0ha1EBQhto3jgCCFDL7XSqXfymw2Z9qyKZV66kDrdodbVHKUp30WZF4Gg73iuS4adUTG tQXdpAolAUjdqw6S4iIwNWneXZ/H72a54LQeeOba7T/IoP32n9yw+07uNBYaIncBYI5v Of1Tzqxz1gKKJ0CcFu0fOvAzZXvT+NcgIfX3KsS4YlbBxUl09o0Td/axZSpNyJT3mhU6 IU4+I2mEzUn+mETk5ywLBmk93TnPsQ+Z1iluXja15GuJozDnNEe0xJJVyohanmcu7Hv9 SoNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lkv7hQWd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s7-20020a05620a29c700b00746a5623849si3067569qkp.463.2023.04.14.09.05.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Apr 2023 09:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lkv7hQWd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLvB-0006qo-Fw; Fri, 14 Apr 2023 12:05:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pnLuk-0006S3-Q2 for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:47 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLui-0007z7-Du for qemu-devel@nongnu.org; Fri, 14 Apr 2023 12:04:42 -0400 Received: by mail-wr1-x431.google.com with SMTP id r20so2227606wra.5 for ; Fri, 14 Apr 2023 09:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681488277; x=1684080277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=87Eys71a5bFDwpsmcqiXjalsGOMTQZkXpUaxljHCLjI=; b=Lkv7hQWdIlA2sElrxSUtHPNg4UUF+/pMmmAB5iBfBiSP6hz/+L1/iAytdkjdaALLr8 F1GVjHMQ99qOBDE23t2pXSpoFe0kUvHQBbNg7jPSYR/BVBtOo3hRjuhRfNcd88/luB9N rBpCIzB1Y9tY+p72b+QRHqRtXGJC+4USvPU9TqNQZbbwJEfMPD0ivv8p/sNwonnMdH76 2IrAaCqe7w7YVX8cHy543Q2idXIgyZZDDDlg6pxvpUQMMzbCmVhfle3Clmw7mYNcKfE5 ANOQFG9xHDCz5+tkO6hd9ozTrgmcX9boEez6MwSvCZt4YwKcXBMe3PgChfnO+LdSdwG/ YmMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681488277; x=1684080277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=87Eys71a5bFDwpsmcqiXjalsGOMTQZkXpUaxljHCLjI=; b=jpuUgpW3ZUSxFT5vC180nYckjg9G47WAOOQpsBsHvmGsyyP7Kndge6PXYLTkuO/nTC ZNQzULQww3/v7H3rghuz7AUUmYaSXXUOspcxj5A3ndI/Ld5A8G9JmsucMm7uygsa1sin HOyFXJbWejy7qa2IZP85FXjNAGM5V+6x6z/l1H/AzINLlByL6lnqAZI/xwaOCw2vH6f2 3jPqrXyg449rNVABSO6pxYi4JV9EzCXD6q4l8hVb2fSy3T+nCtZ7vgt5s52HmhpbExyf o7MQ+dGxfJhqJtdKhiqcxlJmVAq8WxLT7tX+RrVELSKviYG1kMAJQFYGiTqy/pHuUw2Z dfZA== X-Gm-Message-State: AAQBX9dSzAIMR/YfsiBCRWJ+K5JWkKxHth9Ytvm4NVWyU9PQsDKbOX0+ xqafG9bx+ayVgq+ALl65GVH9vA== X-Received: by 2002:a5d:6587:0:b0:2ce:a6f6:edca with SMTP id q7-20020a5d6587000000b002cea6f6edcamr4865810wru.55.1681488277527; Fri, 14 Apr 2023 09:04:37 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g4-20020a5d5404000000b002efb121b75fsm3830886wrv.58.2023.04.14.09.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 09:04:36 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BBB191FFB7; Fri, 14 Apr 2023 17:04:34 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: "Gonglei (Arei)" , Paolo Bonzini , "Michael S. Tsirkin" , virtio-fs@redhat.com, Erik Schilling , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , Eduardo Habkost , Stefan Hajnoczi , Eric Blake , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Jason Wang , Viresh Kumar , Mathieu Poirier , Gerd Hoffmann , Markus Armbruster Subject: [PATCH 08/12] qom: allow for properties to become "fixed" Date: Fri, 14 Apr 2023 17:04:29 +0100 Message-Id: <20230414160433.2096866-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230414160433.2096866-1-alex.bennee@linaro.org> References: <20230414160433.2096866-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When specialising general purpose objects it is sometimes useful to "fix" some of the properties that were configurable by the base classes. We will use this facility when specialising vhost-user-device. Signed-off-by: Alex Bennée --- qapi/qom.json | 2 ++ include/qom/object.h | 16 +++++++++++++++- qom/object.c | 14 ++++++++++++++ qom/object_interfaces.c | 9 ++++++--- qom/qom-qmp-cmds.c | 1 + softmmu/qdev-monitor.c | 1 + 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index a877b879b9..4cda191f00 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -33,12 +33,14 @@ # @description: if specified, the description of the property. # # @default-value: the default value, if any (since 5.0) +# @fixed: if specified if value has been fixed (since 8.1) # # Since: 1.2 ## { 'struct': 'ObjectPropertyInfo', 'data': { 'name': 'str', 'type': 'str', + 'fixed': 'bool', '*description': 'str', '*default-value': 'any' } } diff --git a/include/qom/object.h b/include/qom/object.h index ef7258a5e1..f18d1a8254 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -97,6 +97,8 @@ struct ObjectProperty ObjectPropertyInit *init; void *opaque; QObject *defval; + /** @fixed: if the property has been fixed at its default */ + bool fixed; }; /** @@ -1111,6 +1113,17 @@ void object_property_set_default_int(ObjectProperty *prop, int64_t value); */ void object_property_set_default_uint(ObjectProperty *prop, uint64_t value); +/** + * object_property_fix_default_uint: + * @prop: the property to be fixed + * @value: the fixed value to be written to the property + * + * When specialising an object it may make send to fix some values and + * not allow them to be changed. This can only be applied to + * properties that previously had a default and now cannot be changed. + */ +void object_property_fix_default_uint(ObjectProperty *prop, uint64_t value); + /** * object_property_find: * @obj: the object @@ -1961,13 +1974,14 @@ size_t object_type_get_instance_size(const char *typename); * object_property_help: * @name: the name of the property * @type: the type of the property + * @fixed: has the value been fixed * @defval: the default value * @description: description of the property * * Returns: a user-friendly formatted string describing the property * for help purposes. */ -char *object_property_help(const char *name, const char *type, +char *object_property_help(const char *name, const char *type, bool fixed, QObject *defval, const char *description); G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref) diff --git a/qom/object.c b/qom/object.c index e25f1e96db..b5aba3ffc8 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1584,6 +1584,20 @@ void object_property_set_default_uint(ObjectProperty *prop, uint64_t value) object_property_set_default(prop, QOBJECT(qnum_from_uint(value))); } +static void object_property_fix_default(ObjectProperty *prop, QObject *defval) +{ + g_assert(prop->init == object_property_init_defval); + g_assert(!prop->fixed); + + prop->defval = defval; + prop->fixed = true; +} + +void object_property_fix_default_uint(ObjectProperty *prop, uint64_t value) +{ + object_property_fix_default(prop, QOBJECT(qnum_from_uint(value))); +} + bool object_property_set_uint(Object *obj, const char *name, uint64_t value, Error **errp) { diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 7d31589b04..e351938f8f 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -161,7 +161,7 @@ void user_creatable_add_qapi(ObjectOptions *options, Error **errp) visit_free(v); } -char *object_property_help(const char *name, const char *type, +char *object_property_help(const char *name, const char *type, bool fixed, QObject *defval, const char *description) { GString *str = g_string_new(NULL); @@ -179,7 +179,9 @@ char *object_property_help(const char *name, const char *type, if (defval) { g_autofree char *def_json = g_string_free(qobject_to_json(defval), false); - g_string_append_printf(str, " (default: %s)", def_json); + g_string_append_printf(str, " (%s: %s)", + fixed ? "fixed" : "default", + def_json); } return g_string_free(str, false); @@ -220,7 +222,8 @@ bool type_print_class_properties(const char *type) g_ptr_array_add(array, object_property_help(prop->name, prop->type, - prop->defval, prop->description)); + prop->fixed, prop->defval, + prop->description)); } g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0); if (array->len > 0) { diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 7c087299de..f4cdf4ddde 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -55,6 +55,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) value->name = g_strdup(prop->name); value->type = g_strdup(prop->type); + value->fixed = prop->fixed; } return props; diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index b8d2c4dadd..b56b2af2f2 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -315,6 +315,7 @@ int qdev_device_help(QemuOpts *opts) g_ptr_array_add(array, object_property_help(prop->value->name, prop->value->type, + prop->value->fixed, prop->value->default_value, prop->value->description)); }