Re: [PATCH 1/3] xfs: create global stats and stats_clear in sysfs

Dave Chinner
2015-09-05T03:31:28Z

On Fri, Sep 04, 2015 at 03:54:08PM -0500, Bill O'Donnell wrote:
> Currently, xfs global stats are in procfs. This patch introduces
> (replicates) the global stats in sysfs. Additionally a stats_clear file
> is introduced in sysfs.
>
....
>
> +int xfs_stats_format(char *buf)
> +{
> + int i, j;
> + int len = 0;
> + __uint64_t xs_xstrat_bytes = 0;
> + __uint64_t xs_write_bytes = 0;
> + __uint64_t xs_read_bytes = 0;
....
> + len += snprintf(buf+len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
> + xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
> + len += snprintf(buf+len, PATH_MAX-len, "debug %u\n",
> +#if defined(DEBUG)
> + 1);
> +#else
> + 0);
> +#endif
> +
> +return len;
> +}

missing tab on return.

....
> +STATIC ssize_t
> +xfs_stats_show(
> + struct kobject *kobject,
> + struct attribute *attr,
> + char *buf)
> +{
> + struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
> +
> + return xfs_attr->show ? xfs_attr->show(buf, NULL) : 0;
> +}
> +
> +STATIC ssize_t
> +xfs_stats_store(
> + struct kobject *kobject,
> + struct attribute *attr,
> + const char *buf,
> + size_t count)
> +{
> + struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
> +
> + return xfs_attr->store ? xfs_attr->store(buf, count, NULL) : 0;
> +}
> +
> +static struct sysfs_ops xfs_stats_ops = {
> + .show = xfs_stats_show,
> + .store = xfs_stats_store,
> +};

Hmmm, I'm wondering if we can reduce this boiler plate code here.
It's basically indentical to xfs_log_show/store and
xfs_dbg_show/store. TO make them indentical, all we need to do is
pass the kobject through as the data object, and have the show/store
function decode it if necessary (i.e. call to_xlog() for the xfs log
attributes). This them means that all the sysfs entries
attributes use the same sysfs_ops structure.

That can be done as a patch on top of this, though (i.e. patch #4).

Cheers,

Dave.
--
Dave Chinner
david@fromorbit.com