Karel Zak [Tue, 28 Nov 2023 13:40:48 +0000 (14:40 +0100)]
libmount: accept '\' as escape for options separator
The libmount library can accept any characters as an option value when
the value is quoted (e.g., foo="b,a,r"). However, overlayfs users have
been using '\' as an escape character (e.g., lowerdir=foo\,bar).
Although this escaping mechanism was never officially supported by
libmount/mount, it worked for the old mount(2) API because it kept the
options string unparsed for the mount(2) syscall.
The introduction of the new mount API, which utilizes fsconfig(2) per
option, has brought attention to this issue.
This patch addresses the problem by introducing official support for
'\' as an escape character for options separator.
Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
References: https://lore.kernel.org/all/CAOQ4uxhgUSPkYAV8SJu-SFszkJcVO3-M4DXf46nJUtXODrPk2g@mail.gmail.com/T/#ma8e6cfc1ce7229abc089e03eed99b23b90d701e5 Signed-off-by: Karel Zak <kzak@redhat.com>
Junxiao Bi [Tue, 7 Nov 2023 18:48:06 +0000 (10:48 -0800)]
losetup: report lost loop devices for finding free loop
commit a6ca0456cc6d("loopdev: report lost loop devices") forgot to
report lost loop device for finding free loop case. With this path,
it will show the following if next free loop device is lost.
# ./losetup -f
/dev/loop1 (lost)
# ./losetup -f /tmp/test.img
lt-losetup: /tmp/test.img: failed to set up loop device: No such file or directory
lt-losetup: device node /dev/loop1 (7:1) is lost. You may use mknod(1) to recover it.
Karel Zak [Fri, 24 Nov 2023 09:21:58 +0000 (10:21 +0100)]
Merge branch 'minor-changes-about-new-filter' of https://github.com/masatake/util-linux
* 'minor-changes-about-new-filter' of https://github.com/masatake/util-linux:
lsfd: (man) document --list-columns as the way to list columns
lsfd: (man) refer to scols-filter(5)
libsmartcols: (man) fix typos
Karel Zak [Fri, 24 Nov 2023 09:21:36 +0000 (10:21 +0100)]
Merge branch 'lslocks--co-holders' of https://github.com/masatake/util-linux
* 'lslocks--co-holders' of https://github.com/masatake/util-linux:
tests: (lslocks) add cases testing HOLDERS column
tests: (cosmetic,lslocks) trim whitespaces at the end of line
tests: (test_mkfds::make-regular-file) add a new parameter, "dupfd"
lslocks: add HOLDERS column
lslocks: store list_add_tail when storing information extracted from /proc/$pid/fdinfo/$fd
tests: (test_mkfds) initialize a proper union member
xalloc.h: add new functions: xstrappend, xstrputc, xstrvfappend, and xstrfappend
lsfd: (refactor) make the code comparing struct lock objects reusable
lslocks: add a missing "break;" in a switch/case statement
lslocks: (preparation) add a fd number to the lock struct when loading lock info from /proc/$pid/fdinfo/$fd
lslocks: (refactor) use a tree for storing lock information extracted from /proc/$pid/fdinfo/$fd
lslocks: (refactor) make the data structure for storing lock information replacable
Karel Zak [Mon, 20 Nov 2023 13:58:08 +0000 (14:58 +0100)]
tests: use scols_column_set_properties() in 'fromfile' sample
The library already can read column properties from a column separated
string. Let's use it in 'fromfile' sample to avoid duplicate code and
to test this function too.
Karel Zak [Mon, 20 Nov 2023 11:53:56 +0000 (12:53 +0100)]
libsmartcols: (samples) remove filter.c
It seems better to use fromfile.c sample where we do not have
hardcoded table data, but it's possible to use data from files (see
tests/ts/libsmartcols/files) as already used in in our tests.
Karel Zak [Mon, 6 Nov 2023 20:45:10 +0000 (21:45 +0100)]
libsmartcols: build filter scanner and parser header files too
* if .c and .h generated in the same time then bison does not duplicate
declarations from .h in .c
* it seems better to generate everything and exclude header files from
git
* the patch excludes autotools YACC support, we need reentrant parser
with some cool features from bison; autotools assumes POSIX
compatibility for YACC (bison -y), we do not need it.
Karel Zak [Mon, 23 Oct 2023 20:34:18 +0000 (22:34 +0200)]
libsmartcols: (filter) normalize param strings
Let's ignore space at the beginning and end of the string. It's
possible that filling functions in applications use extra space to
align data in columns. We need to ignore it.
Karel Zak [Wed, 27 Sep 2023 12:00:38 +0000 (14:00 +0200)]
libsmartcols: introduce column type
Now the column can define JSON-type, this commit introduces data-type.
This type is hint for filters and counters how to convert strings from
cells to raw data.
If the conversion from string is not possible, then application can
define callback for this purpose (aka. "datafunc"), this function has
to return the raw data as a void pointer.
This solution allows to use human readable things in cells (e.g.
"123MiB"), but filters and counters can still use the original data.
Karel Zak [Wed, 27 Sep 2023 10:47:15 +0000 (12:47 +0200)]
libsmartcols: Export internally used types to API
We anticipate a need for improved interaction between applications and
the library in certain scenarios. For instance, when a table contains
strings that cannot be readily converted from strings to numbers
(e.g., strings like "15.3MiB") but the application possesses data in a
more suitable format.
Karel Zak [Tue, 26 Sep 2023 10:52:32 +0000 (12:52 +0200)]
lsblk: add scols counters support
* add --ct-filter <expr> to restrict the next next counters
* add --ct <name>[:<param>:func] to define counter. The counter
assigned to the previously specified filter, if no filter specified
then it's applied to all output lines.
Examples:
$ lsblk --ct "number of block devices"
...
Summary:
21 number of block devices
The filter uses default count() function and is applied to
all lines.
$ lsblk --ct-filter 'TRAN=="nvme"' --ct "number of NVMEs"
...
Summary:
4 number of NVMEs
The filter is restricted by filter.
$ lsblk --bytes
--ct-filter 'TRAN=="sata" && TYPE=="disk"'
--ct "size of all SATAs disks":SIZE:sum
...
Summary: 320083771392 size of all SATAs disks
The counter uses sum() built-in function for specified column (SIZE)
and is restricted by filter.
Karel Zak [Mon, 25 Sep 2023 11:19:49 +0000 (13:19 +0200)]
lsblk: fix in-tree filtering
The function device_to_scols() is used recursively (for children).
It's impossible leave the function on filter status=false, it's
necessary to continue in the tree.
Karel Zak [Wed, 20 Sep 2023 11:47:43 +0000 (13:47 +0200)]
libsmartcols: (filter) Add on-demand data filler
When dealing with really large data sets, we need to reduce overhead
by filtering out unnecessary lines. The traditional approach, using:
lstool | grep <expr>
requires the tool to read all data from the system and then filter out
(and throw away) a lot of data.
The filter-filler now allows us to use an empty line. The filter will
request data through a callback, and when a line passes the filter,
the application can fill in the rest of the columns.
For example, in a query like "FOO > 10 && BAR < 10," libsmartcols will
never ask for "BAR" if "FOO" is smaller than 10. This means the
application doesn't have to gather additional columns.
Karel Zak [Tue, 19 Sep 2023 09:15:15 +0000 (11:15 +0200)]
libsmartcols: Add --highlight option to filter sample
This commit demonstrates another example of how to use the filter. It
also enables testing of two filters for the same table to ensure that
Bison and Flex generate a reentrant parser.