All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux] blk-cgroup: always terminate io.stat lines
@ 2022-01-10 10:37 ` Wolfgang Bumiller
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2022-01-10 10:37 UTC (permalink / raw)
  To: linux-block; +Cc: cgroups, Jens Axboe, Tejun Heo, Christoph Hellwig

With the removal of seq_get_buf in blkcg_print_one_stat, we
cannot make adding the newline conditional on there being
relevant stats because the name has already been written
unconditionally.
Otherwise we may end up with multiple device names in one
line which is confusing and doesn't follow the nested-keyed
file format.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Fixes: 252c651a4c85 ("blk-cgroup: stop using seq_get_buf")
---
I also switched to `seq_puts` as suggested by `checkpatch.pl`

This seemed like the simplest approach, so I thought I'd
send a patch.

On my physical machine, creating a new thin lv and starting
a container on it created lines such as

    253:10 253:5 rbytes=0 wbytes=0 rios=0 wios=1 dbytes=0 dios=0
    ^~~~~~ ^~~~~

This *looks* like the devices might just happen to have the
same stats, but that's not the case (and doesn't follow the
documented format).

With this patch this becomes:

    253:10
    253:5 rbytes=0 wbytes=0 rios=0 wios=1 dbytes=0 dios=0

Let me know if you prefer a different solution. I'm not sure
a temporary buffer that can be discarded would be much
better than the previous seq_get_buf() version. Otherwise
we'd need to change the `pd_stat_fn` interface to collect
the data separately and do the formatting afterwards I
suppose?

 block/blk-cgroup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 663aabfeba18..e3e3e826dff7 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -937,8 +937,7 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
 			has_stats = true;
 	}
 
-	if (has_stats)
-		seq_printf(s, "\n");
+	seq_puts(s, "\n");
 }
 
 static int blkcg_print_stat(struct seq_file *sf, void *v)
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH linux] blk-cgroup: always terminate io.stat lines
@ 2022-01-10 10:37 ` Wolfgang Bumiller
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2022-01-10 10:37 UTC (permalink / raw)
  To: linux-block-u79uwXL29TY76Z2rM5mHXA
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, Jens Axboe, Tejun Heo, Christoph Hellwig

With the removal of seq_get_buf in blkcg_print_one_stat, we
cannot make adding the newline conditional on there being
relevant stats because the name has already been written
unconditionally.
Otherwise we may end up with multiple device names in one
line which is confusing and doesn't follow the nested-keyed
file format.

Signed-off-by: Wolfgang Bumiller <w.bumiller-YTcQvvOqK21BDgjK7y7TUQ@public.gmane.org>
Fixes: 252c651a4c85 ("blk-cgroup: stop using seq_get_buf")
---
I also switched to `seq_puts` as suggested by `checkpatch.pl`

This seemed like the simplest approach, so I thought I'd
send a patch.

On my physical machine, creating a new thin lv and starting
a container on it created lines such as

    253:10 253:5 rbytes=0 wbytes=0 rios=0 wios=1 dbytes=0 dios=0
    ^~~~~~ ^~~~~

This *looks* like the devices might just happen to have the
same stats, but that's not the case (and doesn't follow the
documented format).

With this patch this becomes:

    253:10
    253:5 rbytes=0 wbytes=0 rios=0 wios=1 dbytes=0 dios=0

Let me know if you prefer a different solution. I'm not sure
a temporary buffer that can be discarded would be much
better than the previous seq_get_buf() version. Otherwise
we'd need to change the `pd_stat_fn` interface to collect
the data separately and do the formatting afterwards I
suppose?

 block/blk-cgroup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 663aabfeba18..e3e3e826dff7 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -937,8 +937,7 @@ static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
 			has_stats = true;
 	}
 
-	if (has_stats)
-		seq_printf(s, "\n");
+	seq_puts(s, "\n");
 }
 
 static int blkcg_print_stat(struct seq_file *sf, void *v)
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH linux] blk-cgroup: always terminate io.stat lines
  2022-01-10 10:37 ` Wolfgang Bumiller
  (?)
@ 2022-01-10 13:12 ` kernel test robot
  -1 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2022-01-10 13:12 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5863 bytes --]

Hi Wolfgang,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linux/master]

url:    https://github.com/0day-ci/linux/commits/Wolfgang-Bumiller/blk-cgroup-always-terminate-io-stat-lines/20220110-183914
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 136057256686de39cc3a07c2e39ef6bc43003ff6
config: um-i386_defconfig (https://download.01.org/0day-ci/archive/20220110/202201102157.vMQdZCc7-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/c3b02ad1d968fc1f962c4e9438ebcd22140c3403
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Wolfgang-Bumiller/blk-cgroup-always-terminate-io-stat-lines/20220110-183914
        git checkout c3b02ad1d968fc1f962c4e9438ebcd22140c3403
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=um SUBARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   block/blk-cgroup.c: In function 'blkcg_print_one_stat':
>> block/blk-cgroup.c:891:7: warning: variable 'has_stats' set but not used [-Wunused-but-set-variable]
     891 |  bool has_stats = false;
         |       ^~~~~~~~~


vim +/has_stats +891 block/blk-cgroup.c

ef45fe470e1e54 Boris Burkov      2020-06-01  886  
49cb5168a7c6ab Christoph Hellwig 2021-08-10  887  static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
2ee867dcfa2eae Tejun Heo         2015-08-18  888  {
f73316482977ac Tejun Heo         2019-11-07  889  	struct blkg_iostat_set *bis = &blkg->iostat;
636620b66d5d40 Tejun Heo         2018-07-18  890  	u64 rbytes, wbytes, rios, wios, dbytes, dios;
903d23f0a354f2 Josef Bacik       2018-07-03 @891  	bool has_stats = false;
49cb5168a7c6ab Christoph Hellwig 2021-08-10  892  	const char *dname;
f73316482977ac Tejun Heo         2019-11-07  893  	unsigned seq;
49cb5168a7c6ab Christoph Hellwig 2021-08-10  894  	int i;
b0814361a25cba Tejun Heo         2019-11-05  895  
b0814361a25cba Tejun Heo         2019-11-05  896  	if (!blkg->online)
49cb5168a7c6ab Christoph Hellwig 2021-08-10  897  		return;
b0814361a25cba Tejun Heo         2019-11-05  898  
2ee867dcfa2eae Tejun Heo         2015-08-18  899  	dname = blkg_dev_name(blkg);
2ee867dcfa2eae Tejun Heo         2015-08-18  900  	if (!dname)
49cb5168a7c6ab Christoph Hellwig 2021-08-10  901  		return;
2ee867dcfa2eae Tejun Heo         2015-08-18  902  
252c651a4c854b Christoph Hellwig 2021-08-10  903  	seq_printf(s, "%s ", dname);
903d23f0a354f2 Josef Bacik       2018-07-03  904  
f73316482977ac Tejun Heo         2019-11-07  905  	do {
f73316482977ac Tejun Heo         2019-11-07  906  		seq = u64_stats_fetch_begin(&bis->sync);
2ee867dcfa2eae Tejun Heo         2015-08-18  907  
f73316482977ac Tejun Heo         2019-11-07  908  		rbytes = bis->cur.bytes[BLKG_IOSTAT_READ];
f73316482977ac Tejun Heo         2019-11-07  909  		wbytes = bis->cur.bytes[BLKG_IOSTAT_WRITE];
f73316482977ac Tejun Heo         2019-11-07  910  		dbytes = bis->cur.bytes[BLKG_IOSTAT_DISCARD];
f73316482977ac Tejun Heo         2019-11-07  911  		rios = bis->cur.ios[BLKG_IOSTAT_READ];
f73316482977ac Tejun Heo         2019-11-07  912  		wios = bis->cur.ios[BLKG_IOSTAT_WRITE];
f73316482977ac Tejun Heo         2019-11-07  913  		dios = bis->cur.ios[BLKG_IOSTAT_DISCARD];
f73316482977ac Tejun Heo         2019-11-07  914  	} while (u64_stats_fetch_retry(&bis->sync, seq));
2ee867dcfa2eae Tejun Heo         2015-08-18  915  
903d23f0a354f2 Josef Bacik       2018-07-03  916  	if (rbytes || wbytes || rios || wios) {
903d23f0a354f2 Josef Bacik       2018-07-03  917  		has_stats = true;
252c651a4c854b Christoph Hellwig 2021-08-10  918  		seq_printf(s, "rbytes=%llu wbytes=%llu rios=%llu wios=%llu dbytes=%llu dios=%llu",
636620b66d5d40 Tejun Heo         2018-07-18  919  			rbytes, wbytes, rios, wios,
636620b66d5d40 Tejun Heo         2018-07-18  920  			dbytes, dios);
903d23f0a354f2 Josef Bacik       2018-07-03  921  	}
903d23f0a354f2 Josef Bacik       2018-07-03  922  
07b0fdecb24773 Tejun Heo         2019-07-16  923  	if (blkcg_debug_stats && atomic_read(&blkg->use_delay)) {
d09d8df3a29403 Josef Bacik       2018-07-03  924  		has_stats = true;
252c651a4c854b Christoph Hellwig 2021-08-10  925  		seq_printf(s, " use_delay=%d delay_nsec=%llu",
d09d8df3a29403 Josef Bacik       2018-07-03  926  			atomic_read(&blkg->use_delay),
49cb5168a7c6ab Christoph Hellwig 2021-08-10  927  			atomic64_read(&blkg->delay_nsec));
d09d8df3a29403 Josef Bacik       2018-07-03  928  	}
d09d8df3a29403 Josef Bacik       2018-07-03  929  
903d23f0a354f2 Josef Bacik       2018-07-03  930  	for (i = 0; i < BLKCG_MAX_POLS; i++) {
903d23f0a354f2 Josef Bacik       2018-07-03  931  		struct blkcg_policy *pol = blkcg_policy[i];
903d23f0a354f2 Josef Bacik       2018-07-03  932  
903d23f0a354f2 Josef Bacik       2018-07-03  933  		if (!blkg->pd[i] || !pol->pd_stat_fn)
903d23f0a354f2 Josef Bacik       2018-07-03  934  			continue;
903d23f0a354f2 Josef Bacik       2018-07-03  935  
252c651a4c854b Christoph Hellwig 2021-08-10  936  		if (pol->pd_stat_fn(blkg->pd[i], s))
903d23f0a354f2 Josef Bacik       2018-07-03  937  			has_stats = true;
903d23f0a354f2 Josef Bacik       2018-07-03  938  	}
07b0fdecb24773 Tejun Heo         2019-07-16  939  
c3b02ad1d968fc Wolfgang Bumiller 2022-01-10  940  	seq_puts(s, "\n");
f539da82f21589 Tejun Heo         2019-06-13  941  }
2ee867dcfa2eae Tejun Heo         2015-08-18  942  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-10 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 10:37 [PATCH linux] blk-cgroup: always terminate io.stat lines Wolfgang Bumiller
2022-01-10 10:37 ` Wolfgang Bumiller
2022-01-10 13:12 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.