mirror_iproute2/include
Petr Machata adbe5de966 lib: Move sprint_size() from tc here, add print_size()
When displaying sizes of various sorts, tc commonly uses the function
sprint_size() to format the size into a buffer as a human-readable string.
This string is then displayed either using print_string(), or in some code
even fprintf(). As a result, a typical sequence of code when formatting a
size is something like the following:

	SPRINT_BUF(b);
	print_uint(PRINT_JSON, "foo", NULL, foo);
	print_string(PRINT_FP, NULL, "foo %s ", sprint_size(foo, b));

For a concept as broadly useful as size, it would be better to have a
dedicated function in json_print.

To that end, move sprint_size() from tc_util to json_print. Add helpers
print_size() and print_color_size() that wrap arount sprint_size() and
provide the JSON dispatch as appropriate.

Since print_size() should be the preferred interface, convert vast majority
of uses of sprint_size() to print_size(). Two notable exceptions are:

- q_tbf, which does not show the size as such, but uses the string
  "$human_readable_size/$cell_size" even in JSON. There is simply no way to
  have print_size() emit the same text, because print_size() in JSON mode
  should of course just use the raw number, without human-readable frills.

- q_cake, which relies on the existence of sprint_size() in its macro-based
  formatting helpers. There might be ways to convert this particular case,
  but given q_tbf simply cannot be converted, leave it as is.

Signed-off-by: Petr Machata <me@pmachata.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
2020-12-09 02:30:25 +00:00
..
iptables SPDX license identifiers 2017-11-24 12:21:35 -08:00
libiptc SPDX license identifiers 2017-11-24 12:21:35 -08:00
netinet ss: report ecnseen 2011-11-23 14:51:54 -08:00
uapi Update kernel headers 2020-12-09 02:25:34 +00:00
bpf_api.h examples/bpf: add bpf examples with BTF defined maps 2020-11-24 22:14:08 -07:00
bpf_elf.h bpf: implement btf handling and map annotation 2018-07-17 19:38:44 -07:00
bpf_scm.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
bpf_util.h lib: add libbpf support 2020-11-24 22:14:05 -07:00
cg_map.h ss: introduce cgroup2 cache and helper functions 2020-05-13 14:28:04 +00:00
color.h lib/color: make local functions static 2018-11-19 11:42:44 -08:00
dlfcn.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
ip6tables.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
iptables.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
json_print.h lib: Move sprint_size() from tc here, add print_size() 2020-12-09 02:30:25 +00:00
json_writer.h Merge branch 'iproute2-master' into iproute2-next 2018-12-19 12:02:17 -08:00
libgenl.h genl: remove unnecessary extern 2018-09-10 11:53:07 -07:00
libnetlink.h libnetlink: add nl_print_policy() helper 2020-08-24 21:35:07 -06:00
list.h devlink: Add support for devlink resource abstraction 2018-02-23 08:36:05 -08:00
ll_map.h ll_map: Add function to remove link cache entry by index 2019-02-22 18:51:15 -08:00
mnl_utils.h lib: Extract from devlink/mnlg a helper, mnlu_socket_recv_run() 2020-11-13 19:43:15 -07:00
names.h tc: drop unused name_to_id function 2018-11-19 11:42:44 -08:00
namespace.h netns: make netns_{save,restore} static 2019-06-20 14:30:41 -07:00
rt_names.h iplink: add support for protodown reason 2020-09-01 19:52:13 -06:00
rtm_map.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
utils.h Move the use_iec declaration to the tools 2020-12-09 02:28:43 +00:00
version.h v5.9.0 2020-10-15 15:18:35 -07:00
xt-internal.h SPDX license identifiers 2017-11-24 12:21:35 -08:00
xtables.h tc: adjust xtables_match and xtables_target to changes in recent iptables 2019-06-24 16:12:17 -07:00