From nobody Thu May 2 13:45:22 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1664444479; cv=none; d=zohomail.com; s=zohoarc; b=ivypk2vDoXOeLCLxdkDH3MbfCqp+/2yfRGeDnRfm2jw+1ZkEnjJ++UslAxdvJ4qUn4OYP4RESDQObhvylSzblg2toV/doaylxWiHRMR3IPcVYIB1asx+0w3D9T5hM+HOHCL7Bq6KzGWsTcKxwECaSsb379/WJWaJI4DfizR7mT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664444479; 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=4L5t01RoSvLFc7n/IRLFdqy9eyH/xhBEeEPfT71PCJI=; b=DUmpeI/LNnzRMZSnB8ECRnRpEGi9msOmcVlNxFEUxIpvxtrhQYE4Q/xpwDIDhkdhq5SKMY25PhnJ6F5Ht2bXSM+hjLk/mm/hDE0yKGY6v8i4X78QuMQaMuk4fFZNp5D070POhezPz9QP2+k/xVa0LRx6kDJowNdOWolVXZS7DOo= 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 1664444479988644.0528399465817; Thu, 29 Sep 2022 02:41:19 -0700 (PDT) Received: from localhost ([::1]:50772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odq2f-0003Yi-SK for importer@patchew.org; Thu, 29 Sep 2022 05:41:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odpsT-0006vo-OU for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:49 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odpsR-0001Mt-8a for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:44 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AD32A21B7A; Thu, 29 Sep 2022 09:30:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 62B251348E; Thu, 29 Sep 2022 09:30:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IFzHFsFlNWMEOAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:30:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664443841; h=from:from:reply-to: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=4L5t01RoSvLFc7n/IRLFdqy9eyH/xhBEeEPfT71PCJI=; b=tZlaCsFQFBgpkyp1oI597jo+thrdml/EidW8FBCu+9WTMRwUDPJIfo07qZTrXIkRGqFGZ0 MCEWo3UWzjbZ49zyrbvJ6Ma+d3gPYTEyYnA9OwV7y4W+kSBeGj7uAVLJtA9FWkt5WBDbTm Se91bGz8jCGLsaPaWs8XcRNtzzswCJc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664443841; h=from:from:reply-to: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=4L5t01RoSvLFc7n/IRLFdqy9eyH/xhBEeEPfT71PCJI=; b=G+t10qcUOMHH6UH1ppACxfZhCkt1RXr/bNeENfG4nWNpDrstzuyheGdHblq3HapcrDg/lV V9JvTc0r73cHLHBA== From: Claudio Fontana To: Paolo Bonzini , Richard Henderson , Markus Armbruster , Kevin Wolf Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Claudio Fontana Subject: [PATCH v9 1/5] module: removed unused function argument "mayfail" Date: Thu, 29 Sep 2022 11:30:31 +0200 Message-Id: <20220929093035.4231-2-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220929093035.4231-1-cfontana@suse.de> References: <20220929093035.4231-1-cfontana@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=195.135.220.28; envelope-from=cfontana@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1664444482193100001 mayfail is always passed as false for every invocation throughout the progr= am. It controls whether to printf or not to printf an error on g_module_open failure. Remove this unused argument. Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/module.h | 8 ++++---- softmmu/qtest.c | 2 +- util/module.c | 20 +++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/include/qemu/module.h b/include/qemu/module.h index bd73607104..8c012bbe03 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -61,15 +61,15 @@ typedef enum { #define fuzz_target_init(function) module_init(function, \ MODULE_INIT_FUZZ_TARGET) #define migration_init(function) module_init(function, MODULE_INIT_MIGRATI= ON) -#define block_module_load_one(lib) module_load_one("block-", lib, false) -#define ui_module_load_one(lib) module_load_one("ui-", lib, false) -#define audio_module_load_one(lib) module_load_one("audio-", lib, false) +#define block_module_load_one(lib) module_load_one("block-", lib) +#define ui_module_load_one(lib) module_load_one("ui-", lib) +#define audio_module_load_one(lib) module_load_one("audio-", lib) =20 void register_module_init(void (*fn)(void), module_init_type type); void register_dso_module_init(void (*fn)(void), module_init_type type); =20 void module_call_init(module_init_type type); -bool module_load_one(const char *prefix, const char *lib_name, bool mayfai= l); +bool module_load_one(const char *prefix, const char *lib_name); void module_load_qom_one(const char *type); void module_load_qom_all(void); void module_allow_arch(const char *arch); diff --git a/softmmu/qtest.c b/softmmu/qtest.c index f8acef2628..76eb7bac56 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -756,7 +756,7 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) g_assert(words[1] && words[2]); =20 qtest_send_prefix(chr); - if (module_load_one(words[1], words[2], false)) { + if (module_load_one(words[1], words[2])) { qtest_sendf(chr, "OK\n"); } else { qtest_sendf(chr, "FAIL\n"); diff --git a/util/module.c b/util/module.c index 8ddb0e18f5..8563edd626 100644 --- a/util/module.c +++ b/util/module.c @@ -144,7 +144,7 @@ static bool module_check_arch(const QemuModinfo *modinf= o) return true; } =20 -static int module_load_file(const char *fname, bool mayfail, bool export_s= ymbols) +static int module_load_file(const char *fname, bool export_symbols) { GModule *g_module; void (*sym)(void); @@ -172,10 +172,8 @@ static int module_load_file(const char *fname, bool ma= yfail, bool export_symbols } g_module =3D g_module_open(fname, flags); if (!g_module) { - if (!mayfail) { - fprintf(stderr, "Failed to open module: %s\n", - g_module_error()); - } + fprintf(stderr, "Failed to open module: %s\n", + g_module_error()); ret =3D -EINVAL; goto out; } @@ -208,7 +206,7 @@ out: } #endif =20 -bool module_load_one(const char *prefix, const char *lib_name, bool mayfai= l) +bool module_load_one(const char *prefix, const char *lib_name) { bool success =3D false; =20 @@ -256,7 +254,7 @@ bool module_load_one(const char *prefix, const char *li= b_name, bool mayfail) if (strcmp(modinfo->name, module_name) =3D=3D 0) { /* we depend on other module(s) */ for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { - module_load_one("", *sl, false); + module_load_one("", *sl); } } else { for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { @@ -287,7 +285,7 @@ bool module_load_one(const char *prefix, const char *li= b_name, bool mayfail) for (i =3D 0; i < n_dirs; i++) { fname =3D g_strdup_printf("%s/%s%s", dirs[i], module_name, CONFIG_HOST_DSOSUF); - ret =3D module_load_file(fname, mayfail, export_symbols); + ret =3D module_load_file(fname, export_symbols); g_free(fname); fname =3D NULL; /* Try loading until loaded a module file */ @@ -333,7 +331,7 @@ void module_load_qom_one(const char *type) } for (sl =3D modinfo->objs; *sl !=3D NULL; sl++) { if (strcmp(type, *sl) =3D=3D 0) { - module_load_one("", modinfo->name, false); + module_load_one("", modinfo->name); } } } @@ -354,7 +352,7 @@ void module_load_qom_all(void) if (!module_check_arch(modinfo)) { continue; } - module_load_one("", modinfo->name, false); + module_load_one("", modinfo->name); } module_loaded_qom_all =3D true; } @@ -370,7 +368,7 @@ void qemu_load_module_for_opts(const char *group) } for (sl =3D modinfo->opts; *sl !=3D NULL; sl++) { if (strcmp(group, *sl) =3D=3D 0) { - module_load_one("", modinfo->name, false); + module_load_one("", modinfo->name); } } } --=20 2.26.2 From nobody Thu May 2 13:45:23 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1664444337; cv=none; d=zohomail.com; s=zohoarc; b=kYrEL3pzD6BhlHW+P93ucV4hqC5gJpXY4qTK6rfMs6xOyLvvfQjLEHa5dBdwqajHQOf8fPgRZBm8dmHkjzDPaImVTYDOlQ6KkBw3NJZ/tND8atc+22MWFneNsitVN0kVXBIvDf51fml470wm/Lz+kuZIo3gReiL+HXmHk+6oxpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664444337; 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=xZw8URokMZJLim+cHFQVnCvncK3rUkOV5vhmMTFhqW0=; b=Qm33CkzlgwoWo86NcDh/iKkvZM5mZ0c+wMHTVlWzqO0paGN8nTl43w9lSq/3tAFS1BwHMuTKt1C4Kd1fJYVrCKVc2GEynd4H+9Ax+h4ttBR9Y+uW2M56gxT42y0TNzAM4eItoI5U9KAV2AficpdlkLPw2lrP4hAE+iEI8pAog/8= 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 1664444336995643.2331719143262; Thu, 29 Sep 2022 02:38:56 -0700 (PDT) Received: from localhost ([::1]:45558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odq0M-0001er-No for importer@patchew.org; Thu, 29 Sep 2022 05:38:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odpsX-0006wG-EF for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:50 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odpsR-0001Mv-PW for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:45 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1027F21E30; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B57E31348E; Thu, 29 Sep 2022 09:30:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SDsBK8FlNWMEOAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:30:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664443842; h=from:from:reply-to: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=xZw8URokMZJLim+cHFQVnCvncK3rUkOV5vhmMTFhqW0=; b=teYX9EjTNBEOFXknrMktFLv17r0G+cSNOavgmpfQgJlmjrx+eIozSm5etLv6+0RqrynvRL s/VajyzFl5Ee/lsvpQmBzEhtIOSiTfOs3CTUE+APJNOgVJwpv6cpv4iGSexT9j22x201II kD9WH4OuDUdYNWkNMM/luw9hDPxCImk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664443842; h=from:from:reply-to: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=xZw8URokMZJLim+cHFQVnCvncK3rUkOV5vhmMTFhqW0=; b=wkQznK9H7qUSCrdasU5dMXfbcQxG3RtzYnDdby236pUuB55vY/tOww1NHsTlfj3JuI3GcO 4kidzwrfmGDEl6AQ== From: Claudio Fontana To: Paolo Bonzini , Richard Henderson , Markus Armbruster , Kevin Wolf Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Claudio Fontana Subject: [PATCH v9 2/5] module: rename module_load_one to module_load Date: Thu, 29 Sep 2022 11:30:32 +0200 Message-Id: <20220929093035.4231-3-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220929093035.4231-1-cfontana@suse.de> References: <20220929093035.4231-1-cfontana@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=195.135.220.28; envelope-from=cfontana@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1664444338818100001 Signed-off-by: Claudio Fontana Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- audio/audio.c | 2 +- block.c | 4 ++-- block/dmg.c | 4 ++-- hw/core/qdev.c | 2 +- include/qemu/module.h | 10 +++++----- qom/object.c | 4 ++-- softmmu/qtest.c | 2 +- ui/console.c | 6 +++--- util/module.c | 14 +++++++------- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 76b8735b44..0a682336a0 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -79,7 +79,7 @@ audio_driver *audio_driver_lookup(const char *name) } } =20 - audio_module_load_one(name); + audio_module_load(name); QLIST_FOREACH(d, &audio_drivers, next) { if (strcmp(name, d->name) =3D=3D 0) { return d; diff --git a/block.c b/block.c index bc85f46eed..72c7f6d47d 100644 --- a/block.c +++ b/block.c @@ -464,7 +464,7 @@ BlockDriver *bdrv_find_format(const char *format_name) /* The driver isn't registered, maybe we need to load a module */ for (i =3D 0; i < (int)ARRAY_SIZE(block_driver_modules); ++i) { if (!strcmp(block_driver_modules[i].format_name, format_name)) { - block_module_load_one(block_driver_modules[i].library_name); + block_module_load(block_driver_modules[i].library_name); break; } } @@ -976,7 +976,7 @@ BlockDriver *bdrv_find_protocol(const char *filename, for (i =3D 0; i < (int)ARRAY_SIZE(block_driver_modules); ++i) { if (block_driver_modules[i].protocol_name && !strcmp(block_driver_modules[i].protocol_name, protocol)) { - block_module_load_one(block_driver_modules[i].library_name); + block_module_load(block_driver_modules[i].library_name); break; } } diff --git a/block/dmg.c b/block/dmg.c index 98db18d82a..007b8d9996 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -446,8 +446,8 @@ static int dmg_open(BlockDriverState *bs, QDict *option= s, int flags, return -EINVAL; } =20 - block_module_load_one("dmg-bz2"); - block_module_load_one("dmg-lzfse"); + block_module_load("dmg-bz2"); + block_module_load("dmg-lzfse"); =20 s->n_chunks =3D 0; s->offsets =3D s->lengths =3D s->sectors =3D s->sectorcounts =3D NULL; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0806d8fcaa..25dfc08468 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -148,7 +148,7 @@ bool qdev_set_parent_bus(DeviceState *dev, BusState *bu= s, Error **errp) DeviceState *qdev_new(const char *name) { if (!object_class_by_name(name)) { - module_load_qom_one(name); + module_load_qom(name); } return DEVICE(object_new(name)); } diff --git a/include/qemu/module.h b/include/qemu/module.h index 8c012bbe03..b7911ce791 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -61,16 +61,16 @@ typedef enum { #define fuzz_target_init(function) module_init(function, \ MODULE_INIT_FUZZ_TARGET) #define migration_init(function) module_init(function, MODULE_INIT_MIGRATI= ON) -#define block_module_load_one(lib) module_load_one("block-", lib) -#define ui_module_load_one(lib) module_load_one("ui-", lib) -#define audio_module_load_one(lib) module_load_one("audio-", lib) +#define block_module_load(lib) module_load("block-", lib) +#define ui_module_load(lib) module_load("ui-", lib) +#define audio_module_load(lib) module_load("audio-", lib) =20 void register_module_init(void (*fn)(void), module_init_type type); void register_dso_module_init(void (*fn)(void), module_init_type type); =20 void module_call_init(module_init_type type); -bool module_load_one(const char *prefix, const char *lib_name); -void module_load_qom_one(const char *type); +bool module_load(const char *prefix, const char *lib_name); +void module_load_qom(const char *type); void module_load_qom_all(void); void module_allow_arch(const char *arch); =20 diff --git a/qom/object.c b/qom/object.c index d34608558e..4f834f3bf6 100644 --- a/qom/object.c +++ b/qom/object.c @@ -526,7 +526,7 @@ void object_initialize(void *data, size_t size, const c= har *typename) =20 #ifdef CONFIG_MODULES if (!type) { - module_load_qom_one(typename); + module_load_qom(typename); type =3D type_get_by_name(typename); } #endif @@ -1033,7 +1033,7 @@ ObjectClass *module_object_class_by_name(const char *= typename) oc =3D object_class_by_name(typename); #ifdef CONFIG_MODULES if (!oc) { - module_load_qom_one(typename); + module_load_qom(typename); oc =3D object_class_by_name(typename); } #endif diff --git a/softmmu/qtest.c b/softmmu/qtest.c index 76eb7bac56..fc5b733c63 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -756,7 +756,7 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) g_assert(words[1] && words[2]); =20 qtest_send_prefix(chr); - if (module_load_one(words[1], words[2])) { + if (module_load(words[1], words[2])) { qtest_sendf(chr, "OK\n"); } else { qtest_sendf(chr, "FAIL\n"); diff --git a/ui/console.c b/ui/console.c index 765892f84f..4913c55684 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2632,7 +2632,7 @@ bool qemu_display_find_default(DisplayOptions *opts) =20 for (i =3D 0; i < (int)ARRAY_SIZE(prio); i++) { if (dpys[prio[i]] =3D=3D NULL) { - ui_module_load_one(DisplayType_str(prio[i])); + ui_module_load(DisplayType_str(prio[i])); } if (dpys[prio[i]] =3D=3D NULL) { continue; @@ -2650,7 +2650,7 @@ void qemu_display_early_init(DisplayOptions *opts) return; } if (dpys[opts->type] =3D=3D NULL) { - ui_module_load_one(DisplayType_str(opts->type)); + ui_module_load(DisplayType_str(opts->type)); } if (dpys[opts->type] =3D=3D NULL) { error_report("Display '%s' is not available.", @@ -2680,7 +2680,7 @@ void qemu_display_help(void) printf("none\n"); for (idx =3D DISPLAY_TYPE_NONE; idx < DISPLAY_TYPE__MAX; idx++) { if (!dpys[idx]) { - ui_module_load_one(DisplayType_str(idx)); + ui_module_load(DisplayType_str(idx)); } if (dpys[idx]) { printf("%s\n", DisplayType_str(dpys[idx]->type)); diff --git a/util/module.c b/util/module.c index 8563edd626..ad89cd50dc 100644 --- a/util/module.c +++ b/util/module.c @@ -206,7 +206,7 @@ out: } #endif =20 -bool module_load_one(const char *prefix, const char *lib_name) +bool module_load(const char *prefix, const char *lib_name) { bool success =3D false; =20 @@ -254,7 +254,7 @@ bool module_load_one(const char *prefix, const char *li= b_name) if (strcmp(modinfo->name, module_name) =3D=3D 0) { /* we depend on other module(s) */ for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { - module_load_one("", *sl); + module_load("", *sl); } } else { for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { @@ -312,7 +312,7 @@ bool module_load_one(const char *prefix, const char *li= b_name) =20 static bool module_loaded_qom_all; =20 -void module_load_qom_one(const char *type) +void module_load_qom(const char *type) { const QemuModinfo *modinfo; const char **sl; @@ -331,7 +331,7 @@ void module_load_qom_one(const char *type) } for (sl =3D modinfo->objs; *sl !=3D NULL; sl++) { if (strcmp(type, *sl) =3D=3D 0) { - module_load_one("", modinfo->name); + module_load("", modinfo->name); } } } @@ -352,7 +352,7 @@ void module_load_qom_all(void) if (!module_check_arch(modinfo)) { continue; } - module_load_one("", modinfo->name); + module_load("", modinfo->name); } module_loaded_qom_all =3D true; } @@ -368,7 +368,7 @@ void qemu_load_module_for_opts(const char *group) } for (sl =3D modinfo->opts; *sl !=3D NULL; sl++) { if (strcmp(group, *sl) =3D=3D 0) { - module_load_one("", modinfo->name); + module_load("", modinfo->name); } } } @@ -378,7 +378,7 @@ void qemu_load_module_for_opts(const char *group) =20 void module_allow_arch(const char *arch) {} void qemu_load_module_for_opts(const char *group) {} -void module_load_qom_one(const char *type) {} +void module_load_qom(const char *type) {} void module_load_qom_all(void) {} =20 #endif --=20 2.26.2 From nobody Thu May 2 13:45:23 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1664445629; cv=none; d=zohomail.com; s=zohoarc; b=jvX+bglqK7jvldT+K7jn5a7sEHBzcfWD5Na8ECZ6OJWP426+0t8PSkzrTxCZ23IVk3VXqhE8uMQhob6XhA8DcYAs/ZwgNWZsrQLm3R76mBxQ7/1YsETaEnnotwpV7ivVvkiq3vSh2lXOGQsJoCDOuT/Ddy7dVbLjB7jB7xS9RuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664445629; h=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=PDoxGwJEwqqrI9l1T6YYaf5T/JPivr3tnoBBRj4jv3M=; b=akL/CQ/TB5DZ01GRaLot4sYBZiv+8arr4cS97UXrgUVMlpLXPs5Igc6I8okSwLWJQa0ybrRtaU7S5sQosYPV4yEibKRXVSKmmSQUy0d/8WNN0okllk+to1ko4t/5mgJn+mPszDw4DYev44Z86ya9OZFOgKwuy2e+2Xoc9TVp6PA= 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 1664445629256124.66923123813149; Thu, 29 Sep 2022 03:00:29 -0700 (PDT) Received: from localhost ([::1]:51298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odqLC-0007F9-DD for importer@patchew.org; Thu, 29 Sep 2022 06:00:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odpsX-0006wO-FS for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:50 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:36720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odpsR-0001N6-Py for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:47 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 73E011F8A4; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 199271348E; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SHfhBMJlNWMEOAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:30:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664443842; h=from:from:reply-to: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=PDoxGwJEwqqrI9l1T6YYaf5T/JPivr3tnoBBRj4jv3M=; b=lApt+QiDyXnNeghQHLt/KFSj0zqkMTsEfLRjEXff4/fOTv/C+F1yF0rEqno4KZu582J4sA G9WcpQsc4ahK7RhE6+7pWVL3d4vIYVD7d7Fit0pQ/spy8BcJtvOveu3DxgoBqvRmH0wrTQ 1JFhvagpNGQtt/423wXa12QLbtpVlLY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664443842; h=from:from:reply-to: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=PDoxGwJEwqqrI9l1T6YYaf5T/JPivr3tnoBBRj4jv3M=; b=fieJUtt66wurK6VGnZ36RCqZYvN1AUZpfnwmS6v7pmK50P93g6KR8nVSvmu/xgdofPyQ5y bKyFOmMLDP2b7fAA== From: Claudio Fontana To: Paolo Bonzini , Richard Henderson , Markus Armbruster , Kevin Wolf Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Claudio Fontana Subject: [PATCH v9 3/5] module: add Error arguments to module_load and module_load_qom Date: Thu, 29 Sep 2022 11:30:33 +0200 Message-Id: <20220929093035.4231-4-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220929093035.4231-1-cfontana@suse.de> References: <20220929093035.4231-1-cfontana@suse.de> 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=195.135.220.29; envelope-from=cfontana@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1664445631159100001 Content-Type: text/plain; charset="utf-8" improve error handling during module load, by changing: bool module_load(const char *prefix, const char *lib_name); void module_load_qom(const char *type); to: int module_load(const char *prefix, const char *name, Error **errp); int module_load_qom(const char *type, Error **errp); where the return value is: -1 on module load error, and errp is set with the error 0 on module or one of its dependencies are not installed 1 on module load success 2 on module load success (module already loaded or built-in) module_load_qom_one has been introduced in: commit 28457744c345 ("module: qom module support"), which built on top of module_load_one, but discarded the bool return value. Restore it. Adapt all callers to emit errors, or ignore them, or fail hard, as appropriate in each context. Replace the previous emission of errors via fprintf in _some_ error conditions with Error and error_report, so as to emit to the appropriate target. A memory leak is also fixed as part of the module_load changes. audio: when attempting to load an audio module, report module load errors. Note that still for some callers, a single issue may generate multiple error reports, and this could be improved further. Regarding the audio code itself, audio_add() seems to ignore errors, and this should probably be improved. block: when attempting to load a block module, report module load errors. For the code paths that already use the Error API, take advantage of those to report module load errors into the Error parameter. For the other code paths, we currently emit the error, but this could be improved further by adding Error parameters to all possible code paths. console: when attempting to load a display module, report module load error= s. qdev: when creating a new qdev Device object (DeviceState), report load err= ors. If a module cannot be loaded to create that device, now abort executi= on (if no CONFIG_MODULE) or exit (if CONFIG_MODULE). qom/object.c: when initializing a QOM object, or looking up class_by_name, report module load errors. qtest: when processing the "module_load" qtest command, report errors in the load of the module. Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson --- audio/audio.c | 16 ++-- block.c | 20 +++- block/dmg.c | 14 ++- hw/core/qdev.c | 17 +++- include/qemu/module.h | 37 +++++++- qom/object.c | 18 +++- softmmu/qtest.c | 8 +- ui/console.c | 18 +++- util/module.c | 209 +++++++++++++++++++++++------------------- 9 files changed, 234 insertions(+), 123 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 0a682336a0..ea51793843 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -72,20 +72,24 @@ void audio_driver_register(audio_driver *drv) audio_driver *audio_driver_lookup(const char *name) { struct audio_driver *d; + Error *local_err =3D NULL; + int rv; =20 QLIST_FOREACH(d, &audio_drivers, next) { if (strcmp(name, d->name) =3D=3D 0) { return d; } } - - audio_module_load(name); - QLIST_FOREACH(d, &audio_drivers, next) { - if (strcmp(name, d->name) =3D=3D 0) { - return d; + rv =3D audio_module_load(name, &local_err); + if (rv > 0) { + QLIST_FOREACH(d, &audio_drivers, next) { + if (strcmp(name, d->name) =3D=3D 0) { + return d; + } } + } else if (rv < 0) { + error_report_err(local_err); } - return NULL; } =20 diff --git a/block.c b/block.c index 72c7f6d47d..7a94739aed 100644 --- a/block.c +++ b/block.c @@ -464,12 +464,18 @@ BlockDriver *bdrv_find_format(const char *format_name) /* The driver isn't registered, maybe we need to load a module */ for (i =3D 0; i < (int)ARRAY_SIZE(block_driver_modules); ++i) { if (!strcmp(block_driver_modules[i].format_name, format_name)) { - block_module_load(block_driver_modules[i].library_name); + Error *local_err =3D NULL; + int rv =3D block_module_load(block_driver_modules[i].library_n= ame, + &local_err); + if (rv > 0) { + return bdrv_do_find_format(format_name); + } else if (rv < 0) { + error_report_err(local_err); + } break; } } - - return bdrv_do_find_format(format_name); + return NULL; } =20 static int bdrv_format_is_whitelisted(const char *format_name, bool read_o= nly) @@ -976,12 +982,16 @@ BlockDriver *bdrv_find_protocol(const char *filename, for (i =3D 0; i < (int)ARRAY_SIZE(block_driver_modules); ++i) { if (block_driver_modules[i].protocol_name && !strcmp(block_driver_modules[i].protocol_name, protocol)) { - block_module_load(block_driver_modules[i].library_name); + int rv =3D block_module_load(block_driver_modules[i].library_n= ame, errp); + if (rv > 0) { + drv1 =3D bdrv_do_find_protocol(protocol); + } else if (rv < 0) { + return NULL; + } break; } } =20 - drv1 =3D bdrv_do_find_protocol(protocol); if (!drv1) { error_setg(errp, "Unknown protocol '%s'", protocol); } diff --git a/block/dmg.c b/block/dmg.c index 007b8d9996..837f18aa20 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -445,9 +445,17 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, if (!bs->file) { return -EINVAL; } - - block_module_load("dmg-bz2"); - block_module_load("dmg-lzfse"); + /* + * NB: if uncompress submodules are absent, + * ie block_module_load return value =3D=3D 0, the function pointers + * dmg_uncompress_bz2 and dmg_uncompress_lzfse will be NULL. + */ + if (block_module_load("dmg-bz2", errp) < 0) { + return -EINVAL; + } + if (block_module_load("dmg-lzfse", errp) < 0) { + return -EINVAL; + } =20 s->n_chunks =3D 0; s->offsets =3D s->lengths =3D s->sectors =3D s->sectorcounts =3D NULL; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 25dfc08468..0145501904 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -147,8 +147,21 @@ bool qdev_set_parent_bus(DeviceState *dev, BusState *b= us, Error **errp) =20 DeviceState *qdev_new(const char *name) { - if (!object_class_by_name(name)) { - module_load_qom(name); + ObjectClass *oc =3D object_class_by_name(name); +#ifdef CONFIG_MODULES + if (!oc) { + int rv =3D module_load_qom(name, &error_fatal); + if (rv > 0) { + oc =3D object_class_by_name(name); + } else { + error_report("could not find a module for type '%s'", name); + exit(1); + } + } +#endif + if (!oc) { + error_report("unknown type '%s'", name); + abort(); } return DEVICE(object_new(name)); } diff --git a/include/qemu/module.h b/include/qemu/module.h index b7911ce791..c37ce74b16 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -61,16 +61,43 @@ typedef enum { #define fuzz_target_init(function) module_init(function, \ MODULE_INIT_FUZZ_TARGET) #define migration_init(function) module_init(function, MODULE_INIT_MIGRATI= ON) -#define block_module_load(lib) module_load("block-", lib) -#define ui_module_load(lib) module_load("ui-", lib) -#define audio_module_load(lib) module_load("audio-", lib) +#define block_module_load(lib, errp) module_load("block-", lib, errp) +#define ui_module_load(lib, errp) module_load("ui-", lib, errp) +#define audio_module_load(lib, errp) module_load("audio-", lib, errp) =20 void register_module_init(void (*fn)(void), module_init_type type); void register_dso_module_init(void (*fn)(void), module_init_type type); =20 void module_call_init(module_init_type type); -bool module_load(const char *prefix, const char *lib_name); -void module_load_qom(const char *type); + +/* + * module_load: attempt to load a module from a set of directories + * + * directories searched are: + * - getenv("QEMU_MODULE_DIR") + * - get_relocated_path(CONFIG_QEMU_MODDIR); + * - /var/run/qemu/${version_dir} + * + * prefix: a subsystem prefix, or the empty string ("audio-", ...,= "") + * name: name of the module + * errp: error to set in case the module is found, but load fail= ed. + * + * Return value: -1 on error (errp set if not NULL). + * 0 if module or one of its dependencies are not installe= d, + * 1 if the module is found and loaded, + * 2 if the module is already loaded, or module is built-i= n. + */ +int module_load(const char *prefix, const char *name, Error **errp); + +/* + * module_load_qom: attempt to load a module to provide a QOM type + * + * type: the type to be provided + * errp: error to set. + * + * Return value: as per module_load. + */ +int module_load_qom(const char *type, Error **errp); void module_load_qom_all(void); void module_allow_arch(const char *arch); =20 diff --git a/qom/object.c b/qom/object.c index 4f834f3bf6..45da07980a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -526,8 +526,13 @@ void object_initialize(void *data, size_t size, const = char *typename) =20 #ifdef CONFIG_MODULES if (!type) { - module_load_qom(typename); - type =3D type_get_by_name(typename); + 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) { @@ -1033,8 +1038,13 @@ ObjectClass *module_object_class_by_name(const char = *typename) oc =3D object_class_by_name(typename); #ifdef CONFIG_MODULES if (!oc) { - module_load_qom(typename); - oc =3D object_class_by_name(typename); + 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); + } } #endif return oc; diff --git a/softmmu/qtest.c b/softmmu/qtest.c index fc5b733c63..36e28609ff 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -753,12 +753,18 @@ static void qtest_process_command(CharBackend *chr, g= char **words) qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } else if (strcmp(words[0], "module_load") =3D=3D 0) { + Error *local_err =3D NULL; + int rv; g_assert(words[1] && words[2]); =20 qtest_send_prefix(chr); - if (module_load(words[1], words[2])) { + rv =3D module_load(words[1], words[2], &local_err); + if (rv > 0) { qtest_sendf(chr, "OK\n"); } else { + if (rv < 0) { + error_report_err(local_err); + } qtest_sendf(chr, "FAIL\n"); } } else if (qtest_enabled() && strcmp(words[0], "clock_set") =3D=3D 0) { diff --git a/ui/console.c b/ui/console.c index 4913c55684..4e53c3c71b 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2632,7 +2632,11 @@ bool qemu_display_find_default(DisplayOptions *opts) =20 for (i =3D 0; i < (int)ARRAY_SIZE(prio); i++) { if (dpys[prio[i]] =3D=3D NULL) { - ui_module_load(DisplayType_str(prio[i])); + Error *local_err =3D NULL; + int rv =3D ui_module_load(DisplayType_str(prio[i]), &local_err= ); + if (rv < 0) { + error_report_err(local_err); + } } if (dpys[prio[i]] =3D=3D NULL) { continue; @@ -2650,7 +2654,11 @@ void qemu_display_early_init(DisplayOptions *opts) return; } if (dpys[opts->type] =3D=3D NULL) { - ui_module_load(DisplayType_str(opts->type)); + Error *local_err =3D NULL; + int rv =3D ui_module_load(DisplayType_str(opts->type), &local_err); + if (rv < 0) { + error_report_err(local_err); + } } if (dpys[opts->type] =3D=3D NULL) { error_report("Display '%s' is not available.", @@ -2680,7 +2688,11 @@ void qemu_display_help(void) printf("none\n"); for (idx =3D DISPLAY_TYPE_NONE; idx < DISPLAY_TYPE__MAX; idx++) { if (!dpys[idx]) { - ui_module_load(DisplayType_str(idx)); + Error *local_err =3D NULL; + int rv =3D ui_module_load(DisplayType_str(idx), &local_err); + if (rv < 0) { + error_report_err(local_err); + } } if (dpys[idx]) { printf("%s\n", DisplayType_str(dpys[idx]->type)); diff --git a/util/module.c b/util/module.c index ad89cd50dc..32e263163c 100644 --- a/util/module.c +++ b/util/module.c @@ -21,6 +21,7 @@ #include "qemu/module.h" #include "qemu/cutils.h" #include "qemu/config-file.h" +#include "qapi/error.h" #ifdef CONFIG_MODULE_UPGRADES #include "qemu-version.h" #endif @@ -144,25 +145,22 @@ static bool module_check_arch(const QemuModinfo *modi= nfo) return true; } =20 -static int module_load_file(const char *fname, bool export_symbols) +/* + * module_load_dso: attempt to load an existing dso file + * + * fname: full pathname of the file to load + * export_symbols: if true, add the symbols to the global name space + * errp: error to set. + * + * Return value: true on success, false on error, and errp will be set. + */ +static bool module_load_dso(const char *fname, bool export_symbols, + Error **errp) { GModule *g_module; void (*sym)(void); - const char *dsosuf =3D CONFIG_HOST_DSOSUF; - int len =3D strlen(fname); - int suf_len =3D strlen(dsosuf); ModuleEntry *e, *next; - int ret, flags; - - if (len <=3D suf_len || strcmp(&fname[len - suf_len], dsosuf)) { - /* wrong suffix */ - ret =3D -EINVAL; - goto out; - } - if (access(fname, F_OK)) { - ret =3D -ENOENT; - goto out; - } + int flags; =20 assert(QTAILQ_EMPTY(&dso_init_list)); =20 @@ -172,46 +170,38 @@ static int module_load_file(const char *fname, bool e= xport_symbols) } g_module =3D g_module_open(fname, flags); if (!g_module) { - fprintf(stderr, "Failed to open module: %s\n", - g_module_error()); - ret =3D -EINVAL; - goto out; + error_setg(errp, "failed to open module: %s", g_module_error()); + return false; } if (!g_module_symbol(g_module, DSO_STAMP_FUN_STR, (gpointer *)&sym)) { - fprintf(stderr, "Failed to initialize module: %s\n", - fname); - /* Print some info if this is a QEMU module (but from different bu= ild), - * this will make debugging user problems easier. */ + error_setg(errp, "failed to initialize module: %s", fname); + /* + * Print some info if this is a QEMU module (but from different bu= ild), + * this will make debugging user problems easier. + */ if (g_module_symbol(g_module, "qemu_module_dummy", (gpointer *)&sy= m)) { - fprintf(stderr, - "Note: only modules from the same build can be loaded.= \n"); + error_append_hint(errp, + "Only modules from the same build can be loaded.\n"); } g_module_close(g_module); - ret =3D -EINVAL; - } else { - QTAILQ_FOREACH(e, &dso_init_list, node) { - e->init(); - register_module_init(e->init, e->type); - } - ret =3D 0; + return false; } =20 + QTAILQ_FOREACH(e, &dso_init_list, node) { + e->init(); + register_module_init(e->init, e->type); + } trace_module_load_module(fname); QTAILQ_FOREACH_SAFE(e, &dso_init_list, node, next) { QTAILQ_REMOVE(&dso_init_list, e, node); g_free(e); } -out: - return ret; + return true; } -#endif =20 -bool module_load(const char *prefix, const char *lib_name) +int module_load(const char *prefix, const char *name, Error **errp) { - bool success =3D false; - -#ifdef CONFIG_MODULES - char *fname =3D NULL; + int rv =3D -1; #ifdef CONFIG_MODULE_UPGRADES char *version_dir; #endif @@ -219,54 +209,29 @@ bool module_load(const char *prefix, const char *lib_= name) char *dirs[5]; char *module_name; int i =3D 0, n_dirs =3D 0; - int ret; bool export_symbols =3D false; static GHashTable *loaded_modules; const QemuModinfo *modinfo; const char **sl; =20 if (!g_module_supported()) { - fprintf(stderr, "Module is not supported by system.\n"); - return false; + error_setg(errp, "%s", "this platform does not support GLib module= s"); + return -1; } =20 if (!loaded_modules) { loaded_modules =3D g_hash_table_new(g_str_hash, g_str_equal); } =20 - module_name =3D g_strdup_printf("%s%s", prefix, lib_name); + /* allocate all resources managed by the out: label here */ + module_name =3D g_strdup_printf("%s%s", prefix, name); =20 if (g_hash_table_contains(loaded_modules, module_name)) { g_free(module_name); - return true; + return 2; /* module already loaded */ } g_hash_table_add(loaded_modules, module_name); =20 - for (modinfo =3D module_info; modinfo->name !=3D NULL; modinfo++) { - if (modinfo->arch) { - if (strcmp(modinfo->name, module_name) =3D=3D 0) { - if (!module_check_arch(modinfo)) { - return false; - } - } - } - if (modinfo->deps) { - if (strcmp(modinfo->name, module_name) =3D=3D 0) { - /* we depend on other module(s) */ - for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { - module_load("", *sl); - } - } else { - for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { - if (strcmp(module_name, *sl) =3D=3D 0) { - /* another module depends on us */ - export_symbols =3D true; - } - } - } - } - } - search_dir =3D getenv("QEMU_MODULE_DIR"); if (search_dir !=3D NULL) { dirs[n_dirs++] =3D g_strdup_printf("%s", search_dir); @@ -279,46 +244,87 @@ bool module_load(const char *prefix, const char *lib_= name) '_'); dirs[n_dirs++] =3D g_strdup_printf("/var/run/qemu/%s", version_dir); #endif - assert(n_dirs <=3D ARRAY_SIZE(dirs)); =20 - for (i =3D 0; i < n_dirs; i++) { - fname =3D g_strdup_printf("%s/%s%s", - dirs[i], module_name, CONFIG_HOST_DSOSUF); - ret =3D module_load_file(fname, export_symbols); - g_free(fname); - fname =3D NULL; - /* Try loading until loaded a module file */ - if (!ret) { - success =3D true; - break; + /* end of resources managed by the out: label */ + + for (modinfo =3D module_info; modinfo->name !=3D NULL; modinfo++) { + if (modinfo->arch) { + if (strcmp(modinfo->name, module_name) =3D=3D 0) { + if (!module_check_arch(modinfo)) { + error_setg(errp, "module arch does not match: " + "expected '%s', got '%s'", module_arch, modinfo->a= rch); + goto out; + } + } + } + if (modinfo->deps) { + if (strcmp(modinfo->name, module_name) =3D=3D 0) { + /* we depend on other module(s) */ + for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { + int subrv =3D module_load("", *sl, errp); + if (subrv <=3D 0) { + rv =3D subrv; + goto out; + } + } + } else { + for (sl =3D modinfo->deps; *sl !=3D NULL; sl++) { + if (strcmp(module_name, *sl) =3D=3D 0) { + /* another module depends on us */ + export_symbols =3D true; + } + } + } } } =20 - if (!success) { + for (i =3D 0; i < n_dirs; i++) { + char *fname =3D g_strdup_printf("%s/%s%s", + dirs[i], module_name, CONFIG_HOST_DS= OSUF); + int ret =3D access(fname, F_OK); + if (ret !=3D 0 && (errno =3D=3D ENOENT || errno =3D=3D ENOTDIR)) { + /* + * if we don't find the module in this dir, try the next one. + * If we don't find it in any dir, that can be fine too: user + * did not install the module. We will return 0 in this case + * with no error set. + */ + g_free(fname); + continue; + } else if (ret !=3D 0) { + /* most common is EACCES here */ + error_setg_errno(errp, errno, "error trying to access %s", fna= me); + } else if (module_load_dso(fname, export_symbols, errp)) { + rv =3D 1; /* module successfully loaded */ + } + g_free(fname); + goto out; + } + rv =3D 0; /* module not found */ + +out: + if (rv <=3D 0) { g_hash_table_remove(loaded_modules, module_name); g_free(module_name); } - for (i =3D 0; i < n_dirs; i++) { g_free(dirs[i]); } - -#endif - return success; + return rv; } =20 -#ifdef CONFIG_MODULES - static bool module_loaded_qom_all; =20 -void module_load_qom(const char *type) +int module_load_qom(const char *type, Error **errp) { const QemuModinfo *modinfo; const char **sl; + int rv =3D 0; =20 if (!type) { - return; + error_setg(errp, "%s", "type is NULL"); + return -1; } =20 trace_module_lookup_object_type(type); @@ -331,15 +337,24 @@ void module_load_qom(const char *type) } for (sl =3D modinfo->objs; *sl !=3D NULL; sl++) { if (strcmp(type, *sl) =3D=3D 0) { - module_load("", modinfo->name); + if (rv > 0) { + error_setg(errp, "multiple modules providing '%s'", ty= pe); + return -1; + } + rv =3D module_load("", modinfo->name, errp); + if (rv < 0) { + return rv; + } } } } + return rv; } =20 void module_load_qom_all(void) { const QemuModinfo *modinfo; + Error *local_err =3D NULL; =20 if (module_loaded_qom_all) { return; @@ -352,7 +367,9 @@ void module_load_qom_all(void) if (!module_check_arch(modinfo)) { continue; } - module_load("", modinfo->name); + if (module_load("", modinfo->name, &local_err) < 0) { + error_report_err(local_err); + } } module_loaded_qom_all =3D true; } @@ -368,7 +385,10 @@ void qemu_load_module_for_opts(const char *group) } for (sl =3D modinfo->opts; *sl !=3D NULL; sl++) { if (strcmp(group, *sl) =3D=3D 0) { - module_load("", modinfo->name); + Error *local_err =3D NULL; + if (module_load("", modinfo->name, &local_err) < 0) { + error_report_err(local_err); + } } } } @@ -378,7 +398,8 @@ void qemu_load_module_for_opts(const char *group) =20 void module_allow_arch(const char *arch) {} void qemu_load_module_for_opts(const char *group) {} -void module_load_qom(const char *type) {} +int module_load(const char *prefix, const char *name, Error **errp) { retu= rn 2; } +int module_load_qom(const char *type, Error **errp) { return 2; } void module_load_qom_all(void) {} =20 #endif --=20 2.26.2 From nobody Thu May 2 13:45:23 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1664444360; cv=none; d=zohomail.com; s=zohoarc; b=DseJ6YIVGYdTwjBmeeTzesHiuz4+ng+92Mpg5xngQGJ9vhp7MlxokbQ6/8mm4RtJ1ci9u5UQoDL5CzykS1QhtfWO1zx9w2z7OAfP5S4tZ4Xdr77tVrSIUR9MS1yuUE5R7L1wXynyqBvOscMpNegB5Ce/GDqfilKbagrlKNXDftg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664444360; h=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=a6YoHEee2pfrTpGYtw1z4uT+FzqoIVpfKwczmy+I1hU=; b=Kfbknhay26o61ChTe9gl42vPg3DicjXC6pMT28z0LiBj2PrnoFyKScBCNIcmVZJzPPZqg954Id63r2tig729aTOSZf8NWZTerXpLTblwZCtC/Dsu1KrBVyV9sdCwo3dZtU22JTBk0FKn2Rmn+91BUWy7nayRQdhOscUFt0Hto9s= 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 1664444360102927.6124083978996; Thu, 29 Sep 2022 02:39:20 -0700 (PDT) Received: from localhost ([::1]:54240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odq0k-00027G-Pk for importer@patchew.org; Thu, 29 Sep 2022 05:39:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odpsU-0006vr-0R for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:49 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:59994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odpsS-0001NC-3F for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:45 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CCDDE21E37; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7A2F113A7F; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mEVlHMJlNWMEOAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:30:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664443842; h=from:from:reply-to: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=a6YoHEee2pfrTpGYtw1z4uT+FzqoIVpfKwczmy+I1hU=; b=GTWFYiMVSTN4q7JP3SexxzQxg7XpBgT2BTp7flJ5yg/LNUs3SNKaIaTqSclhGGJpEyAhk6 4YLdA88hGmizIUcTF510C9TZ6TN707pa5YvVffXTZmZiclOnChx3dWJLSogfuBMDrLrnPj kOF+vToXXXkHpilL9jnZz/6fJFw4234= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664443842; h=from:from:reply-to: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=a6YoHEee2pfrTpGYtw1z4uT+FzqoIVpfKwczmy+I1hU=; b=3oJSkyj6uBIsYfnV2PUjwzjIAFoD0AAnZtZidmacCvGH/JBfGWK+DcgiqJHHljFM7T68x8 1K8sCA4CGkjWUWDg== From: Claudio Fontana To: Paolo Bonzini , Richard Henderson , Markus Armbruster , Kevin Wolf Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Claudio Fontana Subject: [PATCH v9 4/5] dmg: warn when opening dmg images containing blocks of unknown type Date: Thu, 29 Sep 2022 11:30:34 +0200 Message-Id: <20220929093035.4231-5-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220929093035.4231-1-cfontana@suse.de> References: <20220929093035.4231-1-cfontana@suse.de> 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=195.135.220.28; envelope-from=cfontana@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, 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" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1664444361517100001 Content-Type: text/plain; charset="utf-8" From: Kevin Wolf Signed-off-by: Kevin Wolf Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson --- block/dmg.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/dmg.c b/block/dmg.c index 837f18aa20..96f8c2d14f 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -254,6 +254,25 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHea= derState *ds, for (i =3D s->n_chunks; i < s->n_chunks + chunk_count; i++) { s->types[i] =3D buff_read_uint32(buffer, offset); if (!dmg_is_known_block_type(s->types[i])) { + switch (s->types[i]) { + case UDBZ: + warn_report_once("dmg-bzip2 module is missing, accessing b= zip2 " + "compressed blocks will result in I/O err= ors"); + break; + case ULFO: + warn_report_once("dmg-lzfse module is missing, accessing l= zfse " + "compressed blocks will result in I/O err= ors"); + break; + case UDCM: + case UDLE: + /* Comments and last entry can be ignored without problems= */ + break; + default: + warn_report_once("Image contains chunks of unknown type %x= , " + "accessing them will result in I/O errors= ", + s->types[i]); + break; + } chunk_count--; i--; offset +=3D 40; --=20 2.26.2 From nobody Thu May 2 13:45:23 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1664444977; cv=none; d=zohomail.com; s=zohoarc; b=F+3CfWSPtkd5NplAbLnPV26m3u0hKMp4PGbN7y4QNAgk2HadlBrg1czInIEMGiC9X1srmpfdud4U5lf4QYhyE08nsQOc694jDU73K77rR2SQU1Z9Cq67YznPDViUR2WqOXOMfwID5TCzLl4yJ7lVf5djnPnuhiKPZGuIGKLSmUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664444977; 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=R6T8kiXEFNJEHznxsn2jM0RB4ZpVuiVkxLuwnThSOgo=; b=LdBgg9q7WZhhgqyCMxrdsZcBeMskao3jyk4eFBC+q5WOxEbaJtPLAD3qIr2UKufKU70EXEPYCYCIDJgtl5c2PBnYqXpxxWR+ZdkKOovqq7Ov7q8jY3yhUQjqvkWFSR2szi8L3Wyzeg3AzNwLppBLnQF9uLGdy11UMl7nSdMNq58= 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 1664444977874978.570519259741; Thu, 29 Sep 2022 02:49:37 -0700 (PDT) Received: from localhost ([::1]:36248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odqAi-00015K-PE for importer@patchew.org; Thu, 29 Sep 2022 05:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odpsV-0006vs-0p for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:49 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:44684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odpsS-0001NE-8K for qemu-devel@nongnu.org; Thu, 29 Sep 2022 05:30:45 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 318C91F8D3; Thu, 29 Sep 2022 09:30:43 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D3B431348E; Thu, 29 Sep 2022 09:30:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WPg7MsJlNWMEOAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 09:30:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664443843; h=from:from:reply-to: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=R6T8kiXEFNJEHznxsn2jM0RB4ZpVuiVkxLuwnThSOgo=; b=s7bYYJFodK0cBFvSuiqbwMTkGlT9m4UTDt2deDA145sjeO4Q9uxZ1tn1NPhbsIa7gvc4MF S0R4kBqEwdbuReCcOqvV1mPe2/RdRmRRlHPI4430xAV5ge2n8hPbPubpSXIihYesjXwcb5 P3peAywb3y4jtGeoLHvJ62zbypvq/IY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664443843; h=from:from:reply-to: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=R6T8kiXEFNJEHznxsn2jM0RB4ZpVuiVkxLuwnThSOgo=; b=3GjI+44NAErsS86aHMv0oUGvxjB8eKzEkX0nHC0sEHnywhC1KiutGrkYF1JkTS4kDEiQLw 6MMp7j+dKe8YYqBA== From: Claudio Fontana To: Paolo Bonzini , Richard Henderson , Markus Armbruster , Kevin Wolf Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Claudio Fontana Subject: [PATCH v9 5/5] accel: abort if we fail to load the accelerator plugin Date: Thu, 29 Sep 2022 11:30:35 +0200 Message-Id: <20220929093035.4231-6-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220929093035.4231-1-cfontana@suse.de> References: <20220929093035.4231-1-cfontana@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2001:67c:2178:6::1d; envelope-from=cfontana@suse.de; helo=smtp-out2.suse.de 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 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" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1664444979902100001 if QEMU is configured with modules enabled, it is possible that the load of an accelerator module will fail. Exit in this case, relying on module_object_class_by_name to report the specific load error if any. Signed-off-by: Claudio Fontana Reviewed-by: Richard Henderson [claudio: changed abort() to exit(1)] Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- accel/accel-softmmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/accel/accel-softmmu.c b/accel/accel-softmmu.c index 67276e4f52..f9cdafb148 100644 --- a/accel/accel-softmmu.c +++ b/accel/accel-softmmu.c @@ -66,6 +66,7 @@ void accel_init_ops_interfaces(AccelClass *ac) { const char *ac_name; char *ops_name; + ObjectClass *oc; AccelOpsClass *ops; =20 ac_name =3D object_class_get_name(OBJECT_CLASS(ac)); @@ -73,8 +74,13 @@ void accel_init_ops_interfaces(AccelClass *ac) =20 ops_name =3D g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name); ops =3D ACCEL_OPS_CLASS(module_object_class_by_name(ops_name)); + oc =3D module_object_class_by_name(ops_name); + if (!oc) { + error_report("fatal: could not load module for type '%s'", ops_nam= e); + exit(1); + } g_free(ops_name); - + ops =3D ACCEL_OPS_CLASS(oc); /* * all accelerators need to define ops, providing at least a mandatory * non-NULL create_vcpu_thread operation. --=20 2.26.2