From nobody Thu Nov 28 07:57:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693844774; cv=none; d=zohomail.com; s=zohoarc; b=mbk/dp8nQKdhg13e8TZrlqsAIjHy8P+yNx07DXplX7MkzRj4omA015vW/cPTYyL14FbUI4A0HhAN8aSzTZrq1wPJdVtW5bjP5Vp+xsk9E+7aEAkew5TFM5XqHKwk7aL3sYN+FR7H0ztJoQNTO+580djPh5P/MP8bdfPcQCvAcEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693844774; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=opO8x/u1gtxbDGBKSy77Ei+EC+dcGTIytP3c3BLnam4=; b=MMpKeliNNSse7J2Ahjxi/MXQU2HwjmXnoCRVzpmf9nnQhpzAV/WWhNVpQMrXmYabBlGF+nY0vd0UM3siP6Sur76Vmj6TPBQt67rbQUaMNbpjfgHH1Ln07+UP+6mnsQ7xFcrfFC4QaUv4KDGXO5Bl5qskJtOPAnBsNI6xLWQ1vEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693844774385376.5330313569914; Mon, 4 Sep 2023 09:26:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdCOi-0007OC-W3; Mon, 04 Sep 2023 12:25:57 -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 1qdCOg-0007Mn-8Z for qemu-devel@nongnu.org; Mon, 04 Sep 2023 12:25:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdCOd-0001s1-Rc for qemu-devel@nongnu.org; Mon, 04 Sep 2023 12:25:54 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-10-cJqZhMOUNy-Vm4ep4HuxCw-1; Mon, 04 Sep 2023 12:25:48 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67271299E75A; Mon, 4 Sep 2023 16:25:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63C25493110; Mon, 4 Sep 2023 16:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693844751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=opO8x/u1gtxbDGBKSy77Ei+EC+dcGTIytP3c3BLnam4=; b=NoHVLkeB6KYLs4quusMnsThW6PQoaN4yBqPIm2Cw6RWBw6QAwoNBYE2+w4EA2UmbE9XIqB x5cYQlnAXTHwCKi/KYb5d6lzS8xeaYFXYHJSPGFem10OueN8qvs9Fkcir98igVxFJkhJSA YQABsfq21yfJKBVyqJRhWvwtl+FYjc4= X-MC-Unique: cJqZhMOUNy-Vm4ep4HuxCw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , William Tsai , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Maydell , Eduardo Habkost , Kevin Wolf Subject: [PATCH 1/1] qom: fix setting of array properties Date: Mon, 4 Sep 2023 17:25:44 +0100 Message-ID: <20230904162544.2388037-2-berrange@redhat.com> In-Reply-To: <20230904162544.2388037-1-berrange@redhat.com> References: <20230904162544.2388037-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693844775909100003 DEFINE_PROP_ARRAY() creates a property 'len-$ARRAY-PROP-NAME' which, when set, will create a sequence of '$ARRAY-PROP-NAME[N]' properties. This only works if the 'len-$ARRAY-PROP-NAME' property is set first, and the array elements afterwards. Historically this required the user to set correct ordering and QemuOpts traversal would preserve that ordering. With QemuOpts now converted to QDict, iteration ordering is undefined. Thus to keep array properties working, we iterate over the QDict twice. Doing this in QOM is a bit of a layering violation since DEFINE_PROP_ARRAY is part of QDev, but it is the simplest option to preserve backwards compatibility, without ripple effects across any other part of QEMU. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1090 Signed-off-by: Daniel P. Berrang=C3=A9 --- qom/object_interfaces.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 7d31589b04..6aaaf42ffc 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -51,7 +51,37 @@ static void object_set_properties_from_qdict(Object *obj= , const QDict *qdict, if (!visit_start_struct(v, NULL, NULL, 0, errp)) { return; } + + /* Layering violation here... + * + * DEFINE_PROP_ARRAY() creates a property 'len-$ARRAY-PROP-NAME' + * which, when set, will create a sequence of '$ARRAY-PROP-NAME[N]' + * properties. + * + * This only works if the 'len-$ARRAY-PROP-NAME' property is + * set first, and the array elements afterwards. Historically + * this required the user to get correct ordering and QemuOpts + * traversal would preserve that ordering. With QemuOpts now + * converted to QDict, iteration ordering is undefined. Thus + * to keep array properties working, we iterate over the QDict + * twice. + */ + + /* First the props that control array property length */ for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { + if (!g_str_has_prefix(e->key, "len-")) { + continue; + } + if (!object_property_set(obj, e->key, v, errp)) { + goto out; + } + } + + /* Then any other normal properties */ + for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { + if (g_str_has_prefix(e->key, "len-")) { + continue; + } if (!object_property_set(obj, e->key, v, errp)) { goto out; } --=20 2.41.0