From nobody Sat Nov 23 21:03:50 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=1730204853; cv=none; d=zohomail.com; s=zohoarc; b=FAP0GlMDHgVZCP3iSZjRVGBbFUFxvC/Bh7rr68biU+VKQIWtEcHRGRc4Shl8LRt3fZ241cE+j4hPni+tmfTr4HhSJ/14/4D9ryWfSjrjCtbHOOAroBnpXlCJkk7tPAAfz63H3e2yDN2JWx3X4udBSBnLa4aYyg8KI/x2R+rcpr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730204853; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ig1z+rhJdSJSO97leX3ay0AjAoKtPA0I38pbsYq3HOE=; b=GAp8Vp3bIP8y23J7QrCYyOuwLhzAMCpzTE7CgNry0/G5kTcCkCEfkN62C6dvTNZbOBoP4QUL3kigfxYHyi5BjACHS0W8Jmy6z3ZJGgmdjSWVhLV7dqd8JGmwZqzfC5v/S8y9PbsRpT/kXmjcnAAe0WyUMYiPfgvioAbO/9wWvzo= 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 1730204853007103.76736482772617; Tue, 29 Oct 2024 05:27:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5lIz-00069S-Qh; Tue, 29 Oct 2024 08:26:37 -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 1t5lIo-00067z-8M for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:26:27 -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 1t5lIl-0000Tk-Ci for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:26:25 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-WflVo-hLPOKLl2dYMWcoYg-1; Tue, 29 Oct 2024 08:26:20 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d45de8bbfso3778015f8f.3 for ; Tue, 29 Oct 2024 05:26:20 -0700 (PDT) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b712bfsm12356488f8f.79.2024.10.29.05.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 05:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730204782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ig1z+rhJdSJSO97leX3ay0AjAoKtPA0I38pbsYq3HOE=; b=LK9+JRANovaWuznRT+Z7tIsEeSedEk/qgN/MLXSce3Xf/Yrv/hdsx4pABfF5GKS8xCkyPZ Pv0uwrx/vmBJf5mgo539YbXvIUlIQkDv7E5oJFSDzac3enrGk9E20C3NFjcQGw4TwqgkOg 2d3Psrk1DPXObRQ0h0kt4hG8Fj0fSdE= X-MC-Unique: WflVo-hLPOKLl2dYMWcoYg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730204779; x=1730809579; 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=Ig1z+rhJdSJSO97leX3ay0AjAoKtPA0I38pbsYq3HOE=; b=kzfDXky8NmJAP4HvDj76Gc71zqaSKk261N8uoT5m6WOgLWahy6YC3yQQ6Wr6Wp330Y ndyXAB+QVze97P55gcgtnl1kP+kblzHjMxiu7mYmCd15k2dHEhEYVBTYste+IGX7ZLtx 4dM8g1VFTUvg6H1pufvysY9SCA2YOZTHMV/kfRAtGFS9JTkYUvmdYyFTQfbOhpWDXdtT divwu0x93b7vJT210zHapvId7d5UsEYjq4BEYbe5FbkfBLKVLHRilU/3k3tRWOOiIG92 tIe3IZoXJpOYtRLtKsF1qm/rmBH8nHyI9twAF7+m6iiS8luiO6ofaVhK/6GFUjfTd7/h +noQ== X-Gm-Message-State: AOJu0Ywv2CyEXUzD+9yVxkN4/wdYE82/Fjd9ibxS18vmgTJBZ9EX8m9k ZZgQkbO1mvUQyuLLKI0VEBmYtGzb+05QmQU+VgzhsbkFgUdLz1VlsoPghyLDTK56dU0ZekJPB/O sqKpljgUmZwBrPPOj6a+AywhavMyhfMf7b9OmSrByhVQn+HC+KB+sCHzN4SToHTw5qAfNGy5mdQ ikTADYlkktYJ6Lti8S1tc9PNCGqaVzlZPJkeysaXo= X-Received: by 2002:a05:6000:b88:b0:37d:397a:5a05 with SMTP id ffacd0b85a97d-38061248a2dmr9833228f8f.54.1730204777244; Tue, 29 Oct 2024 05:26:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcVTAPJfFql+QmVu7qlNmzBuX/DgsRrJJWTmbw2QpBeS84m6dkJ9fsVQanQ4abYW1CWIVriw== X-Received: by 2002:a05:6000:b88:b0:37d:397a:5a05 with SMTP id ffacd0b85a97d-38061248a2dmr9833205f8f.54.1730204776827; Tue, 29 Oct 2024 05:26:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com Subject: [PATCH 3/5] qom: centralize module-loading functionality Date: Tue, 29 Oct 2024 13:26:07 +0100 Message-ID: <20241029122609.514347-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241029122609.514347-1-pbonzini@redhat.com> References: <20241029122609.514347-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.302, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1730204854116116600 Content-Type: text/plain; charset="utf-8" Put together the common code of object_initialize() and module_object_class_by_name() into a function that supports Error **. Rename the existing function type_get_by_name() to clarify that it will only look at defined types; this is often okay within object.c to look at the parents, but not outside it. Signed-off-by: Paolo Bonzini --- qom/object.c | 72 ++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/qom/object.c b/qom/object.c index 8b269414488..29155c64639 100644 --- a/qom/object.c +++ b/qom/object.c @@ -195,7 +195,7 @@ void type_register_static_array(const TypeInfo *infos, = int nr_infos) } } =20 -static TypeImpl *type_get_by_name(const char *name) +static TypeImpl *type_get_by_name_noload(const char *name) { if (name =3D=3D NULL) { return NULL; @@ -204,10 +204,32 @@ static TypeImpl *type_get_by_name(const char *name) return type_table_lookup(name); } =20 +static TypeImpl *type_get_or_load_by_name(const char *name, Error **errp) +{ + TypeImpl *type =3D type_get_by_name_noload(name); + +#ifdef CONFIG_MODULES + if (!type) { + int rv =3D module_load_qom(name, errp); + if (rv > 0) { + type =3D type_get_by_name_noload(name); + } else { + error_prepend(errp, "could not load a module for type '%s'", n= ame); + return NULL; + } + } +#endif + if (!type) { + error_setg(errp, "unknown type '%s'", name); + } + + return type; +} + static TypeImpl *type_get_parent(TypeImpl *type) { if (!type->parent_type && type->parent) { - type->parent_type =3D type_get_by_name(type->parent); + type->parent_type =3D type_get_by_name_noload(type->parent); if (!type->parent_type) { fprintf(stderr, "Type '%s' is missing its parent '%s'\n", type->name, type->parent); @@ -363,7 +385,7 @@ static void type_initialize(TypeImpl *ti) } =20 for (i =3D 0; i < ti->num_interfaces; i++) { - TypeImpl *t =3D type_get_by_name(ti->interfaces[i].typename); + TypeImpl *t =3D type_get_by_name_noload(ti->interfaces[i].type= name); if (!t) { error_report("missing interface '%s' for object '%s'", ti->interfaces[i].typename, parent->name); @@ -557,23 +579,7 @@ static void object_initialize_with_type(Object *obj, s= ize_t size, TypeImpl *type =20 void object_initialize(void *data, size_t size, const char *typename) { - TypeImpl *type =3D type_get_by_name(typename); - -#ifdef CONFIG_MODULES - if (!type) { - int rv =3D module_load_qom(typename, &error_fatal); - if (rv > 0) { - type =3D type_get_by_name(typename); - } else { - error_report("missing object type '%s'", typename); - exit(1); - } - } -#endif - if (!type) { - error_report("missing object type '%s'", typename); - abort(); - } + TypeImpl *type =3D type_get_or_load_by_name(typename, &error_fatal); =20 object_initialize_with_type(data, size, type); } @@ -784,7 +790,7 @@ Object *object_new_with_class(ObjectClass *klass) =20 Object *object_new(const char *typename) { - TypeImpl *ti =3D type_get_by_name(typename); + TypeImpl *ti =3D type_get_by_name_noload(typename); =20 return object_new_with_type(ti); } @@ -957,7 +963,7 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *cla= ss, return class; } =20 - target_type =3D type_get_by_name(typename); + target_type =3D type_get_by_name_noload(typename); if (!target_type) { /* target class type unknown, so fail the cast */ return NULL; @@ -1055,7 +1061,7 @@ const char *object_class_get_name(ObjectClass *klass) =20 ObjectClass *object_class_by_name(const char *typename) { - TypeImpl *type =3D type_get_by_name(typename); + TypeImpl *type =3D type_get_by_name_noload(typename); =20 if (!type) { return NULL; @@ -1068,21 +1074,15 @@ ObjectClass *object_class_by_name(const char *typen= ame) =20 ObjectClass *module_object_class_by_name(const char *typename) { - ObjectClass *oc; + TypeImpl *type =3D type_get_or_load_by_name(typename, NULL); =20 - oc =3D object_class_by_name(typename); -#ifdef CONFIG_MODULES - if (!oc) { - Error *local_err =3D NULL; - int rv =3D module_load_qom(typename, &local_err); - if (rv > 0) { - oc =3D object_class_by_name(typename); - } else if (rv < 0) { - error_report_err(local_err); - } + if (!type) { + return NULL; } -#endif - return oc; + + type_initialize(type); + + return type->class; } =20 ObjectClass *object_class_get_parent(ObjectClass *class) --=20 2.47.0