linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: sysfs: export dev stats in devinfo directory
Date: Fri, 4 Jun 2021 21:41:09 +0800	[thread overview]
Message-ID: <5aeca0cd-c6b2-939a-6f83-7ea5722076dc@oracle.com> (raw)
In-Reply-To: <20210604132058.11334-1-dsterba@suse.com>

On 4/6/21 9:20 pm, David Sterba wrote:
> The device stats can be read by ioctl, wrapped by command 'btrfs device
> stats'. Provide another source where to read the information in
> /sys/fs/btrfs/FSID/devinfo/DEVID/stats .

  The planned stat here is errors stat.
  So why not rename this to error_stats?

> The format is a list of
> 'key value' pairs one per line, which is common in other stat files.
> The names are the same as used in other device stat outputs.

  Nice!

Thanks, Anand

> The stats are all in one file as it's the snapshot of all available
> stats. The 'one value per file' is not very suitable here. The stats
> should be valid right after the stats item is read from disk, shortly
> after initializing the device, but in any case also print the validity
> status.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
>   fs/btrfs/sysfs.c | 28 ++++++++++++++++++++++++++++
>   1 file changed, 28 insertions(+)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 4b508938e728..3d4c806c4f73 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1495,11 +1495,39 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
>   }
>   BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
>   
> +static ssize_t btrfs_devinfo_stats_show(struct kobject *kobj,
> +		struct kobj_attribute *a, char *buf)
> +{
> +	struct btrfs_device *device = container_of(kobj, struct btrfs_device,
> +						   devid_kobj);
> +
> +	/*
> +	 * Print all at once so we get a snapshot of all values from the same
> +	 * time. Keep them in sync and in order of definition of
> +	 * btrfs_dev_stat_values.
> +	 */
> +	return scnprintf(buf, PAGE_SIZE,
> +		"stats_valid %d\n",
> +		"write_errs %d\n"
> +		"read_errs %d\n"
> +		"flush_errs %d\n"
> +		"corruption_errs %d\n"
> +		"generation_errs %d\n",
> +		!!(device->dev_stats_valid),
> +		btrfs_dev_stat_read(device, BTRFS_DEV_STAT_WRITE_ERRS),
> +		btrfs_dev_stat_read(device, BTRFS_DEV_STAT_READ_ERRS),
> +		btrfs_dev_stat_read(device, BTRFS_DEV_STAT_FLUSH_ERRS),
> +		btrfs_dev_stat_read(device, BTRFS_DEV_STAT_CORRUPTION_ERRS),
> +		btrfs_dev_stat_read(device, BTRFS_DEV_STAT_GENERATION_ERRS));
> +}
> +BTRFS_ATTR(devid, stats, btrfs_devinfo_stats_show);
> +
>   static struct attribute *devid_attrs[] = {
>   	BTRFS_ATTR_PTR(devid, in_fs_metadata),
>   	BTRFS_ATTR_PTR(devid, missing),
>   	BTRFS_ATTR_PTR(devid, replace_target),
>   	BTRFS_ATTR_PTR(devid, scrub_speed_max),
> +	BTRFS_ATTR_PTR(devid, stats),
>   	BTRFS_ATTR_PTR(devid, writeable),
>   	NULL
>   };
> 


  parent reply	other threads:[~2021-06-04 13:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 13:20 [PATCH] btrfs: sysfs: export dev stats in devinfo directory David Sterba
2021-06-04 13:23 ` David Sterba
2021-06-04 13:41 ` Anand Jain [this message]
2021-06-04 14:21   ` David Sterba
2021-06-04 22:38     ` Anand Jain
2021-06-07 18:55       ` David Sterba
2021-06-09  7:43         ` Anand Jain
2021-06-09 15:14           ` David Sterba
2021-06-04 15:13 ` kernel test robot
2021-06-04 16:27 ` kernel test robot
2021-06-09 18:24 ` Omar Sandoval
2021-06-09 18:40   ` Omar Sandoval
2021-06-09 18:50   ` David Sterba
2021-06-10  0:55     ` Omar Sandoval
2021-06-10 16:37       ` David Sterba
2021-06-10 17:54         ` Omar Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5aeca0cd-c6b2-939a-6f83-7ea5722076dc@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).