From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B31A8C433FE for ; Fri, 7 Oct 2022 21:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiJGVaB (ORCPT ); Fri, 7 Oct 2022 17:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiJGV3x (ORCPT ); Fri, 7 Oct 2022 17:29:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A04312678; Fri, 7 Oct 2022 14:29:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AF07EB82472; Fri, 7 Oct 2022 21:29:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E9ADC433C1; Fri, 7 Oct 2022 21:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665178173; bh=xzuCgIx6mYbRdKnGqUJ/lSN6ffMnfBDG+vfaZmXPBmA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kRpwehn/z3ztvaCg9Wa0yp5mHxVnV9WaAgnr4R4ZUYROoWnZ8PXIp7XqOD2UY+qKQ 5Z9AuLk6oPbrdlIl4GGv7G5+tX0XQfhJeK6R4DRgjEsNEot4PNqXYdoCSPvgScXWEb 43icZ0i15FVpJ4XTbvEOjNaWFjc+4l81/SF/qHQ8YE9SpOVtQAxCNY3Hg/oeQV3irS CNH130fSaT47t7EMx3q9D2rb3FNzFCqJgkADln7B6IahiaEdpwhrBUgZgWOSxRuK8x 0+Tt2i7LNnTfvpndzUbLug36JUG4DocI3VOpbzTeqA2NpEsWjjmyT1/kc298rkORso tUy+obSpoEjjQ== Date: Fri, 7 Oct 2022 14:29:32 -0700 From: "Darrick J. Wong" To: Zorro Lang Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: Re: [PATCH 1/2] check: detect and preserve all coredumps made by a test Message-ID: References: <166500906990.887104.14293889638885406232.stgit@magnolia> <166500907546.887104.248083399669088204.stgit@magnolia> <20221007051855.z3om7f5feqtqqkgb@zlang-mailbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221007051855.z3om7f5feqtqqkgb@zlang-mailbox> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org On Fri, Oct 07, 2022 at 01:18:55PM +0800, Zorro Lang wrote: > On Wed, Oct 05, 2022 at 03:31:15PM -0700, Darrick J. Wong wrote: > > From: Darrick J. Wong > > > > If someone sets kernel.core_uses_pid (or kernel.core_pattern), any > > coredumps generated by fstests might have names that are longer than > > just "core". Since the pid isn't all that useful by itself, let's > > record the coredumps by hash when we save them, so that we don't waste > > space storing identical crash dumps. > > > > Signed-off-by: Darrick J. Wong > > --- > > check | 26 ++++++++++++++++++++++---- > > common/rc | 16 ++++++++++++++++ > > 2 files changed, 38 insertions(+), 4 deletions(-) > > > > > > diff --git a/check b/check > > index af23572ccc..654d986b27 100755 > > --- a/check > > +++ b/check > > @@ -913,11 +913,19 @@ function run_section() > > sts=$? > > fi > > > > - if [ -f core ]; then > > - _dump_err_cont "[dumped core]" > > - mv core $RESULT_BASE/$seqnum.core > > + # If someone sets kernel.core_pattern or kernel.core_uses_pid, > > + # coredumps generated by fstests might have a longer name than > > + # just "core". Use globbing to find the most common patterns, > > + # assuming there are no other coredump capture packages set up. > > + local cores=0 > > + for i in core core.*; do > > I'm wondering if it should be "for i in core*" ? The coredump file only can be > "core" with dot ".", can it with "-" or "_" or others? The ".$pid" pattern is encoded in the kernel function format_corename: /* Backward compatibility with core_uses_pid: * * If core_pattern does not include a %p (as is the default) * and core_uses_pid is set, then .%pid will be appended to * the filename. Do not do this for piped commands. */ if (!ispipe && !pid_in_pattern && core_uses_pid) { err = cn_printf(cn, ".%d", task_tgid_vnr(current)); if (err) return err; } Note that even this is an incomplete solution because the sysadmin could configure a totally different corename pattern, pipe it to another program, or whatever, and fstests fails to capture any dumps at all. Longer term it'd be theoretically nice to turn core_pattern into a cgroup-manageable tunable and teach ./check to capture all the coredumps, but I am not volunteering to write that much new infrastructure. :/ --D > > > + test -f "$i" || continue > > + if ((cores++ == 0)); then > > + _dump_err_cont "[dumped core]" > > + fi > > + _save_coredump "$i" > > tc_status="fail" > > - fi > > + done > > > > if [ -f $seqres.notrun ]; then > > $timestamp && _timestamp > > @@ -950,6 +958,16 @@ function run_section() > > # of the check script itself. > > (_adjust_oom_score 250; _check_filesystems) || tc_status="fail" > > _check_dmesg || tc_status="fail" > > + > > + # Save any coredumps from the post-test fs checks > > + for i in core core.*; do > > + test -f "$i" || continue > > + if ((cores++ == 0)); then > > + _dump_err_cont "[dumped core]" > > + fi > > + _save_coredump "$i" > > + tc_status="fail" > > + done > > fi > > > > # Reload the module after each test to check for leaks or > > diff --git a/common/rc b/common/rc > > index d1f3d56bf8..9750d06a9a 100644 > > --- a/common/rc > > +++ b/common/rc > > @@ -4948,6 +4948,22 @@ _create_file_sized() > > return $ret > > } > > > > +_save_coredump() > > +{ > > + local path="$1" > > + > > + local core_hash="$(_md5_checksum "$path")" > > + local out_file="$RESULT_BASE/$seqnum.core.$core_hash" > > + > > + if [ -s "$out_file" ]; then > > + rm -f "$path" > > + return > > + fi > > + rm -f "$out_file" > > + > > + mv "$path" "$out_file" > > +} > > + > > init_rc > > > > ################################################################################ > > >