Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp483029pxb; Tue, 15 Feb 2022 19:22:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhG/xEYn7ildTAnhxxfqqvrCQ8SGdtQtPdgT7wZTIH2wZu2b76sBu4Cwk1Qj3qMakQl6KN X-Received: by 2002:a17:90b:360e:b0:1b9:d9f0:b37 with SMTP id ml14-20020a17090b360e00b001b9d9f00b37mr618801pjb.111.1644981730055; Tue, 15 Feb 2022 19:22:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644981730; cv=none; d=google.com; s=arc-20160816; b=A7yxRrTPRIETx4W7Feo+SIc7SyVVz5+9u8rOiGIWoUhVxC2ptszSYpy7DXn018ZX6k LuEpiOZbwR98+SE6HZURESnyOhjm9CW4M7S4JTsTSjNh2Xpqj/X0KSYA4EsX1t80L07W FjuMg+Bn7Ys9vTkWWnmyaLc2BHL9eNwbSgyTHqhpfgfr0uuvxqtRtoHseYogW8Tfsgke SxhIlBHfbzaEBwsdSGq0QYW7EhF9HTnTt1148NFPPFrvhHCj5U21IaFRTgajVksQ24xj Zn0TW7U/jkE11NN52Yw5QgWm6MaNvuKxt3TL0c5YReNFDHWIB+WK+GO6BE8X/VyG3+N8 Cpuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:references :in-reply-to:subject:cc:to:from:date:mime-version:dkim-signature; bh=9WMcJa9uEnT+UzJmm5PfiJ1edfraV5MByx6rAGY8xSU=; b=oavUpYYalOq8u/fT7tydJ3XxCrpPg3SfcKX67z7IeE12RqcwarxS1AgubZDwVPmkfT 8oA5uSYool9ct2E21XZd2OrtgE1inTggTh/G2OgZlBhrzkaeqiWxYXYfqdK7E728ZP9d 2+ZAZyi5o23F6ELwC/fclp6/MjnAsMR0IlEYEn8cpv2tsTEse4q3OxCAj8LmoK+R0bd7 rFNKsJKfI2H2zlLK6oIiRFS1fFykq7te8V9YYieauUFAURrLECEQL5+spFj8v1s98YMF HwwDZXpAirqromjzcTZRdMB2cOP1mH7647JFdyzrXlo8rQJs/v1ShDTHEje491Cpk/DH TOag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (bad format) header.i=@dorminy.me header.s=mail header.b=c4HMPAjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r17si7941216pfh.90.2022.02.15.19.21.52; Tue, 15 Feb 2022 19:22:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=neutral (bad format) header.i=@dorminy.me header.s=mail header.b=c4HMPAjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241323AbiBOQHS (ORCPT + 99 others); Tue, 15 Feb 2022 11:07:18 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241306AbiBOQHN (ORCPT ); Tue, 15 Feb 2022 11:07:13 -0500 Received: from box.fidei.email (box.fidei.email [IPv6:2605:2700:0:2:a800:ff:feba:dc44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34A53615A; Tue, 15 Feb 2022 08:07:02 -0800 (PST) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 4AAA3805DE; Tue, 15 Feb 2022 11:07:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1644941221; bh=ITdx6H4Vxkkt1psYEw6EmitYVmfA1N7Bq0NJMjPXVbQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=c4HMPAjbq9F1JsH/sS6OZSMR8Aa5gwb/rUTmkRyeIsGxcXdJgSAlYxBnavMzRk3Kt WjVSt7IRFjSy2cnIL8Nyv510FnAa6Ws3exMJrLfZM3ZUb1IfhPbzDIv5jqK+D9Mpo+ 3QrUwvr2Rcg5Lodgu6+qInG29z3ZqqrgsmhAGs9A1VZUI90zgEaWNU4lnCKydFjc+d 84pORfyZQIZryZyICyw1TvYoLMuq1HAtha5NPyoP4/L9jB4MiGr4td16ewp87WNhsX kDq1c/WUHdMQUHH4BqvaFoaad6zp3CP50o1ahjr+zmpqBosi8cc+REXZa1858iEJBu xZJEE3HqcQckQ== MIME-Version: 1.0 Date: Tue, 15 Feb 2022 11:07:01 -0500 From: Sweet Tea Dorminy To: Sweet Tea Dorminy Cc: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] btrfs: add fs state details to error messages. In-Reply-To: <20220215150438.GN12643@twin.jikos.cz> References: <20220212191042.94954-1-sweettea-kernel@dorminy.me> <20220215150438.GN12643@twin.jikos.cz> Message-ID: X-Sender: sweettea-kernel@dorminy.me Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> +static void btrfs_state_to_string(const struct btrfs_fs_info *info, >> char *buf) >> +{ >> + unsigned long state = info->fs_state; >> + char *curr = buf; >> + >> + memcpy(curr, STATE_STRING_PREFACE, sizeof(STATE_STRING_PREFACE)); >> + curr += sizeof(STATE_STRING_PREFACE) - 1; >> + >> + /* If more states are reported, update MAX_STATE_CHARS also */ >> + if (test_and_clear_bit(BTRFS_FS_STATE_ERROR, &state)) > > The state is supposed to be sticky, so can't be cleared. Also as I read > the suggested change, the "state: " should be visible for all messages > that are printed after the filesystem state changes. 'state' is a local copy of info->fs_state, so clearing bits on the local copy should be okay, and the "state: " will be present for everything after the fs state changes. Could instead use test_bit(&info->fs_state) and keep a count of how many states were printed (to know if we need to reset the buffer) if that is clearer. > >> + *curr++ = 'E'; >> + >> + if (test_and_clear_bit(BTRFS_FS_STATE_TRANS_ABORTED, &state)) >> + *curr++ = 'X'; >> + >> + /* If no states were printed, reset the buffer */ >> + if (state == info->fs_state) >> + curr = buf; >> + >> + *curr++ = '\0'; >> +} >> + >> /* >> * Generally the error codes correspond to their respective errors, >> but there >> * are a few special cases. >> @@ -128,6 +153,7 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info >> *fs_info, const char *function >> { >> struct super_block *sb = fs_info->sb; >> #ifdef CONFIG_PRINTK >> + char statestr[sizeof(STATE_STRING_PREFACE) + MAX_STATE_CHARS]; >> const char *errstr; >> #endif >> >> @@ -136,10 +162,11 @@ void __btrfs_handle_fs_error(struct >> btrfs_fs_info *fs_info, const char *function >> * under SB_RDONLY, then it is safe here. >> */ >> if (errno == -EROFS && sb_rdonly(sb)) >> - return; >> + return; > > Unnecessary change. Yeah, there's a stray space at the start of that line, but I can take out fixing it. > >> >> #ifdef CONFIG_PRINTK >> errstr = btrfs_decode_error(errno); >> + btrfs_state_to_string(fs_info, statestr); >> if (fmt) { >> struct va_format vaf; >> va_list args; >> @@ -148,12 +175,12 @@ void __btrfs_handle_fs_error(struct >> btrfs_fs_info *fs_info, const char *function >> vaf.fmt = fmt; >> vaf.va = &args; >> >> - pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s (%pV)\n", >> - sb->s_id, function, line, errno, errstr, &vaf); >> + pr_crit("BTRFS: error (device %s%s) in %s:%d: errno=%d %s (%pV)\n", >> + sb->s_id, statestr, function, line, errno, errstr, &vaf); > > Alternatively the state message can be built into the message itself so > it does not require the extra array. > > > pr_crit("btrfs: error(device %s%s%s%s) ...", > sb->s_id, > statebits ? ", state" : "", > test_bit(FS_ERRROR) ? "E" : "", > test_bit(TRANS_ABORT) ? "T" : "", ...); > > This is the idea, final code can use some wrappers around the bit > constatnts. > > >> va_end(args); >> } else { >> - pr_crit("BTRFS: error (device %s) in %s:%d: errno=%d %s\n", >> - sb->s_id, function, line, errno, errstr); >> + pr_crit("BTRFS: error (device %s%s) in %s:%d: errno=%d %s\n", >> + sb->s_id, statestr, function, line, errno, errstr); > > Filling the temporary array makes sense as it's used twice, however I'm > not sure if the 'else' branch is ever executed. There are a bunch of calls with NULL format -> else branch, unfortunately. Thanks!