Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C4C9C38145 for ; Thu, 8 Sep 2022 13:59:57 +0000 (UTC) Received: from localhost ([::1]:58608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oWI4S-0006Wg-AB for qemu-devel@archiver.kernel.org; Thu, 08 Sep 2022 09:59:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oWI3A-0003o4-0Z for qemu-devel@nongnu.org; Thu, 08 Sep 2022 09:58:36 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:35650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oWI38-000899-3x for qemu-devel@nongnu.org; Thu, 08 Sep 2022 09:58:35 -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 75B5C2276E; Thu, 8 Sep 2022 13:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1662645512; 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=pBRY+sj2wjqpq09bs8EVihJ0QLFGRZAl0496fthyf3c=; b=qPusFZxEaqMpgV7owOOKOZx0NlWZEi1Ar5wD8VMWh5EeSfbmoUUfO5TkvuTIgUS3KEFfiS 131hFGQhobHys/uxVHfjGZC+K1KQBPyQSwCR0p9VZjj8zdQXpDKXvDDy3WgH35A1+N/SYx UGNSSKqB1ZuaJRoinhVoUBqXI/JQGbQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1662645512; 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=pBRY+sj2wjqpq09bs8EVihJ0QLFGRZAl0496fthyf3c=; b=8+RJE/MxXa+uAKnMa+2HLRyZPoPB8+ki4wNp0Pl77zY7wUzfI/js6mQ4YJvI4EeTPsneFp D1rwm23J+PYL8ECA== 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 390BE13A6D; Thu, 8 Sep 2022 13:58:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id C6CJDAj1GWPySgAAMHmgww (envelope-from ); Thu, 08 Sep 2022 13:58:32 +0000 Message-ID: Date: Thu, 8 Sep 2022 15:58:31 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH 2/3] module: add Error arguments to module_load_one and module_load_qom_one Content-Language: en-US To: Richard Henderson , Paolo Bonzini Cc: qemu-devel@nongnu.org, dinechin@redhat.com, Gerd Hoffmann , =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , =?UTF-8?Q?Daniel_P_=2e_Berrang=c3=a9?= , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= References: <20220906115501.28581-1-cfontana@suse.de> <20220906115501.28581-3-cfontana@suse.de> <1d5db132-08e3-0767-c672-df99a7aa9f3e@linaro.org> From: Claudio Fontana In-Reply-To: <1d5db132-08e3-0767-c672-df99a7aa9f3e@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=195.135.220.28; envelope-from=cfontana@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -75 X-Spam_score: -7.6 X-Spam_bar: ------- X-Spam_report: (-7.6 / 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, NICE_REPLY_A=-3.142, RCVD_IN_DNSWL_MED=-2.3, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 9/8/22 10:11, Richard Henderson wrote: > On 9/6/22 12:55, Claudio Fontana wrote: >> improve error handling during module load, by changing: >> >> bool module_load_one(const char *prefix, const char *lib_name); >> void module_load_qom_one(const char *type); >> >> to: >> >> bool module_load_one(const char *prefix, const char *name, Error **errp); >> bool module_load_qom_one(const char *type, Error **errp); >> >> 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. >> >> Signed-off-by: Claudio Fontana >> --- >> audio/audio.c | 6 +- >> block.c | 12 +++- >> block/dmg.c | 10 ++- >> hw/core/qdev.c | 10 ++- >> include/qemu/module.h | 10 +-- >> qom/object.c | 15 +++- >> softmmu/qtest.c | 6 +- >> ui/console.c | 19 +++++- >> util/module.c | 155 ++++++++++++++++++++++++++++++------------ >> 9 files changed, 182 insertions(+), 61 deletions(-) >> >> diff --git a/audio/audio.c b/audio/audio.c >> index 76b8735b44..4f4bb10cce 100644 >> --- a/audio/audio.c >> +++ b/audio/audio.c >> @@ -72,6 +72,7 @@ void audio_driver_register(audio_driver *drv) >> audio_driver *audio_driver_lookup(const char *name) >> { >> struct audio_driver *d; >> + Error *local_err = NULL; >> >> QLIST_FOREACH(d, &audio_drivers, next) { >> if (strcmp(name, d->name) == 0) { >> @@ -79,7 +80,10 @@ audio_driver *audio_driver_lookup(const char *name) >> } >> } >> >> - audio_module_load_one(name); >> + if (!audio_module_load_one(name, &local_err) && local_err) { >> + error_report_err(local_err); >> + } > > Why would local_err not be set on failure? Is this the NOTDIR thing? I guess this is > sufficient to distinguish the two cases... The urge to bikeshed the return value is > strong. :-) > >> +bool module_load_one(const char *prefix, const char *name, Error **errp); >> +bool module_load_qom_one(const char *type, Error **errp); > > Doc comments go in the header file. > >> +/* >> + * module_load_file: attempt to load a 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: 0 on success (found and loaded), < 0 on failure. >> + * A return value of -ENOENT or -ENOTDIR means 'not found'. >> + * -EINVAL is used as the generic error condition. >> + * >> + * Error: If fname is found, but could not be loaded, errp is set >> + * with the error encountered during load. >> + */ >> +static int module_load_file(const char *fname, bool export_symbols, >> + Error **errp) >> { >> GModule *g_module; >> void (*sym)(void); >> @@ -152,16 +168,19 @@ static int module_load_file(const char *fname, bool export_symbols) >> int len = strlen(fname); >> int suf_len = strlen(dsosuf); >> ModuleEntry *e, *next; >> - int ret, flags; >> + int flags; >> >> if (len <= suf_len || strcmp(&fname[len - suf_len], dsosuf)) { >> - /* wrong suffix */ >> - ret = -EINVAL; >> - goto out; >> + error_setg(errp, "wrong filename, missing suffix %s", dsosuf); >> + return -EINVAL; >> } >> - if (access(fname, F_OK)) { >> - ret = -ENOENT; >> - goto out; >> + if (access(fname, F_OK) != 0) { >> + int ret = errno; >> + if (ret != ENOENT && ret != ENOTDIR) { >> + error_setg_errno(errp, ret, "error trying to access %s", fname); >> + } >> + /* most likely is EACCES here */ >> + return -ret; >> } > > I looked at this a couple of days ago and came to the conclusion that the split between > this function and its caller is wrong. > > The directory path probe loop is currently split between the two functions. I think the > probe loop should be in the caller (i.e. the access call here moved out). I think > module_load_file should only be called once the file is known to exist. Which then > simplifies the set of errors to be returned from here. > > (I might even go so far as to say module_load_file should be moved into module_load_one, > because there's not really much here, and it would reduce ifdefs.) > > > r~ I missed that module_load_one contains basically an #ifdef CONFIG_MODULES inside it. It's just a big #ifdef CONFIG_MDOULES in disguise, it is really confusing. I'll try to make things more explicit.