Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3328053pxb; Sun, 3 Oct 2021 23:02:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzL919YP1EE22kdOPwBV2dOrR6oMcuzpwsGTmVbjlpU9wklF/NwHY8C6WTIzb5/mUCy+tN1 X-Received: by 2002:a17:902:7e4b:b0:13d:c03f:5946 with SMTP id a11-20020a1709027e4b00b0013dc03f5946mr21557034pln.4.1633327339377; Sun, 03 Oct 2021 23:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633327339; cv=none; d=google.com; s=arc-20160816; b=HkrxYtG97QusBxNiTlWiYynqllQfim8h2BmFJrIlAbnOVpqKKCQ2SCPdNjhLDYyg+l 26qtKsEq7jdOp0IIAtYlso9na2YoqulUpekh7rpUqCdXH7CB9CA+WtkHm52IeFTgr7fd GB/Pd83rjJtQORHKY3Dsv7lBjSKpUUaFbTpYcnBgYSfCM05ykfCKVjKWY/5fuo9d/eil PyYjTKl8famMnF3lAZHmAtMK1M0auwYP1NO3oMy9fRAAte7naqg5GE73pw7UJgU4uHuE xF15NqRt4GzJvI8tG3D7hK3apeyVcZCaAZVyY+hpMydEdwhdFMqRmaqca2EYZksgu+TV xwLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:date:message-id :references:reply-to:subject:in-reply-to:cc:to:from:dkim-signature; bh=oCkr7Fku8LUZeYfw26iyJBI+OKqI0i7U20SUwLXqqlI=; b=Jy2JCHMV5LrRSzrH8K0PAL00kWN8QZPZJ+/8CYa8KI19Ux1ycAb/Z8w756OFeo5IDq TrBL6HsfXkkTpI6UzYHGZpw7Y+waGeVaFB9pN0/KceNzN4jtVWrbM5ajKLWJy5GlZkB8 n+RfeRPV8LXkhlsSlJjru5sbKsaiHcnXP22OWZYHOW68Hxl5qUCYmj69lPQWXR9LLKOZ x+nDWN8JtJFWTwx+O8D0JS7eKd9bG4yCcIVycJnh5/oDd5dfmvjQ8HLWjEl3QFhU8E/F vX9hV3y9w+8Xmu6k9zOfjKpXYpZXHBReLUnZv3gpBcZthQntOou/arF4v6Nw+IKHvZTC lvVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=C34tpHZ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id on5si18565635pjb.9.2021.10.03.23.02.04; Sun, 03 Oct 2021 23:02:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=C34tpHZ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232496AbhJDGAR (ORCPT + 99 others); Mon, 4 Oct 2021 02:00:17 -0400 Received: from mout.gmx.net ([212.227.17.22]:35283 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbhJDGAO (ORCPT ); Mon, 4 Oct 2021 02:00:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1633327086; bh=3yQaFDx3HteINXfvXksHTXMue8daiL/SfDc07itzYXc=; h=X-UI-Sender-Class:From:To:CC:In-reply-to:Subject:Reply-to: References:Date; b=C34tpHZ63vLX2lWlplKZFtVaP6QSvYENnT6CFy2STHzNlqVz6XIbbCVYNpsVDRDFW BvUgClE9pCVUUxYhMc1YPkYEkWqZf2PTkH9pwOmCoR9ymLNJywMEsPuMdMeYeZNjwq N49SJynqauYZwpzibAWPNzLet2y4i1eho40ozId8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from corona.crabdance.com ([173.228.106.131]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M3lYB-1mWzjq2m5T-000wlv; Mon, 04 Oct 2021 07:58:06 +0200 Received: by corona.crabdance.com (Postfix, from userid 1000) id C52AD899CC4; Sun, 3 Oct 2021 22:57:58 -0700 (PDT) From: Stefan Schaeckeler To: richard@nod.at CC: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, sschaeck@cisco.com In-reply-to: <1815586081.32955.1633291105033.JavaMail.zimbra@nod.at> (message from Richard Weinberger on Sun, 3 Oct 2021 21:58:25 +0200 (CEST)) Subject: Re: [PATCH 1/1] ubifs: ubifs to export filesystem error counters Content-Type: text/plain Reply-to: schaecsn@gmx.net References: <20210907214034.11676-1-schaecsn@gmx.net> <20210907214034.11676-2-schaecsn@gmx.net> <1815586081.32955.1633291105033.JavaMail.zimbra@nod.at> Message-Id: <20211004055758.C52AD899CC4@corona.crabdance.com> Date: Sun, 3 Oct 2021 22:57:58 -0700 (PDT) X-Provags-ID: V03:K1:Zg0mDQu0TezbLoYA8pDQR0+RMH3KAnGSWTLtVxSkc71qesyBOPr JBAf+vDG++ICxoeTj8f3iQe3YwwWUAK9o9I2YEP0s9tsLe4jckW0gqoysT8GPpP31/HaS2y c4dWeRxMxRVkqy+5NQEhJX/4pSLhLYFcGX35nT709N4wJxjXWKjPlOPlaapuoKzNcn+O2mx WNnJxPshu06YrrT1JY4gQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:mhArpKz+4UI=:iUQjTCYBLI/S7wj60DELtH cFRnjvOicAMHcSqcHAjqmlh1flfDRg/Q7Y9EPM+bXDGJfg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oding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Richard, > > Not all ubifs filesystem errors are propagated to userspace. > > > > Export bad magic, bad node and crc errors via sysfs. This allows users= pace > > to notice filesystem errors: > > > > /sys/fs/ubifs/ubiX_Y/errors_magic > > /sys/fs/ubifs/ubiX_Y/errors_node > > /sys/fs/ubifs/ubiX_Y/errors_crc > > > > The counters are reset to 0 with a remount. Writing anything into the > > counters also clears them. > > I think this is a nice feature. Thanks for implementing it. > Please see some minor nits below. > > Is there a specific reason why you didn't implement it via UBIFS's debug= fs interface? These error counters are not meant for aiding debugging but for userspace = to monitor the sanity of the filesystem. Also ext4 exports error counters via sysfs - it's probably a good idea to be consistent with them. $ dir /sys/fs/ext4/sdb2/*error* -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/errors_count -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_blo= ck -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_err= code -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_fun= c -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_ino -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_lin= e -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/first_error_tim= e -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/last_error_bloc= k -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/last_error_errc= ode -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/last_error_func -r--r--r-- 1 root root 4096 Oct 3 13:47 /sys/fs/ext4/sdb2/last_error_ino -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/last_error_line -r--r--r-- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/last_error_time =2D-w------- 1 root root 4096 Oct 3 13:46 /sys/fs/ext4/sdb2/trigger_fs_er= ror > sysfs is ABI, so we cannot change much anymore. Judging by the filesystem permissions above, ext4 does not seem to allow resetting error counters. If you worry about unchangable ABIs then we coul= d play it safe and don't support write callbacks for resetting the error cou= nters in an initial version of the ubifs sysfs. What do you think? When we are at it, in the current code, writing anything into a sysfs node resets the corresponding counter. One could fine-tune that to set the coun= ter to whatever non-negative integer is passed. > > + if (c->stats) > > + c->stats->magic_errors++; > > Please wrap this into a helper function. Ack. > > + if (c->stats) > > + c->stats->node_errors++; > > Same. Ack. > > + if (c->stats) > > + c->stats->crc_errors++; > > Same. Ack. > > +#define UBIFS_ATTR_FUNC(_name, _mode) UBIFS_ATTR(_name, _mode, _name) > > + > > +UBIFS_ATTR_FUNC(errors_magic, 0644); > > +UBIFS_ATTR_FUNC(errors_crc, 0644); > > +UBIFS_ATTR_FUNC(errors_node, 0644); > > I'm not sure whether everyone should be allowed to read these stats. > dmesg is also restricted these days. An unprivileged user should not see= the > errors he can indirectly trigger. I don't mind 600, but having error counters world-readable is consistent w= ith ext4 (see dir above) and so I suggest to keep 644. > > + case attr_errors_crc: > > + return snprintf(buf, PAGE_SIZE, "%u\n", > > + sbi->stats->crc_errors); > > Please use sysfs_emit(). Ack. > > + if (n =3D=3D UBIFS_DFS_DIR_LEN) { > > + /* The array size is too small */ > > + ret =3D -EINVAL; > > + goto out_last; > > Where is c->stats released in case of an error? My fault. Will be fixed. > > diff --git a/fs/ubifs/sysfs.h b/fs/ubifs/sysfs.h > > new file mode 100644 > > index 000000000000..a10a82585af8 > > --- /dev/null > > +++ b/fs/ubifs/sysfs.h > > Do we really need a new header file? > Usually most run-time stuff of UBIFS is part of ubifs.h. I wanted to be consistent with debugfs where fs/ubifs/debug.c comes with i= ts own header fs/ubifs/debug.h. I'll send out a new patch once we agree on all changes. To recap: - write callbacks: do we remove them? If not, do we keep them as is or do = we fine-tine them by letting a non-negative integer set the counter? - 644 (world-readable) counters to be consistent with ext4? - keep sysfs.h to be consistent with debugfs? Stefan