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.
Karel Zak [Tue, 5 Sep 2023 09:52:39 +0000 (11:52 +0200)]
libsmartcols: (filter) make holders API more generic
The internal implementation is generic (can hold something else than
only column name). Let's make the API also generic. Maybe later we can
support something else than only column names in expressions
(e.g. env.variables ?).
Karel Zak [Thu, 31 Aug 2023 11:47:50 +0000 (13:47 +0200)]
libsmartcols: add parser header files
The header files are generated by bison and flex, but it seems that it's
expected that developer generate it only rarely and manually. So, it
seems better to keep it in git.
libuuid: avoid truncate clocks.txt to improve performance
Instead of explicitly truncating clocks.txt file, pad with
whitespaces in the end of file.
This is done to improve performance of libuuid on xfs
filesystems. Instead of truncating the file, pad it with whitespaces.
This is anyways used as a failsafe method in case truncate fails.
The reason why this regression was introduced was because of: 869ae85dae64 ("xfs: flush new eof page on truncate to avoid post-eof corruption")
An attempt to move the clocks.txt to /run (tmpfs) has been attempted before
[1] and with commit ab2e7dd17 ("libuuid: move clock state file from
/var/lib to /var/run"). The latter was reverted.
Karel Zak [Mon, 13 Nov 2023 09:36:16 +0000 (10:36 +0100)]
Merge branch 'lslocks--per-process' of https://github.com/masatake/util-linux
* 'lslocks--per-process' of https://github.com/masatake/util-linux:
lslocks: (man) update the note about OFDLCK
lslocks: (test) add a case for OFDLCK type locks
lslocks: use information extracted from "locks: " column of /proc/$pid/fdinfo/*
lslocks: (refactor) lift up the code destroying the lock list for future extension
lslocks: rename functions for future extension
lslocks: refactor the code reading /proc/locks
lslocks: (refactor) remove 'pid' global variable
lslocks: (man) document LEASE type
lslocks: (test) add a case
Define cs_min through a define and not a const int to avoid the
following build failure with -O0 raised since version 2.39 and
https://github.com/util-linux/util-linux/commit/2fa4168c8bc9d5438bc1dfadda293c7c21b6fa59:
libuuid/src/gen_uuid.c: In function 'uuid_generate_time_generic':
libuuid/src/gen_uuid.c:536:33: error: initializer element is not constant
THREAD_LOCAL int cache_size = cs_min;
^~~~~~
For consistency, also use define for cs_max and cs_factor
Karel Zak [Wed, 8 Nov 2023 11:35:30 +0000 (12:35 +0100)]
Merge branch 'lsfd--tty' of https://github.com/masatake/util-linux
* 'lsfd--tty' of https://github.com/masatake/util-linux:
tests: (lsfd) add a case testing NAME, SOURCE, ENDPOINTS, and PTMX.TTY-INDEX columns of pts fds
tests: (test_mkfds::pty) add a new factory
lsfd: fill ENDPOINTS column for pty devices
lsfd: add attach_xinfo and get_ipc_class methods to cdev_ops
lsfd: add PTMX.TTY-INDEX column
lsfd: utilize /proc/tty/drivers for filling SOURCE column of tty devices
lsfd: make the order of calling finalize_* and initialize_* consistent
Karel Zak [Thu, 2 Nov 2023 09:41:03 +0000 (10:41 +0100)]
libmount: improve mnt_table_next_child_fs()
The function utilizes the struct libmnt_itr to iterate through the mountinfo file
but neglects the direction specified by the iterator. This a bug. The application
must manage the direction, as, for instance, umount(8) requires the children of
the mountpoint in reverse order.
Fixes: https://github.com/util-linux/util-linux/issues/2552 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 1 Nov 2023 13:47:41 +0000 (14:47 +0100)]
disk-utils: add SPDX and Copyright notices
Explicitly state the license (usually GPL-2.0-or-later; our default)
and include copyright statements in all files to prevent false positive
reports from license analysis tools. Add also add SPDX-License-Identifier
tag to all files.
Junxiao Bi [Wed, 25 Oct 2023 20:36:03 +0000 (13:36 -0700)]
loopdev: report lost loop devices
If a /dev/loopX is lost because someone might have removed it by mistake,
future losetup operations on that loop device will fail and losetup
--all and --list will not report the devices (although kernel still
uses it).
Since /sysfs still have the loop device intact, detect that and report it.
Changes:
* --list and --all add "(lost)" after device node path
# losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop0 (lost) 0 0 0 0 /root/l0.img 0 512
# losetup -a
/dev/loop0 (lost): []: (/root/l0.img)
* use /sys to get devno rather than stat()
* report warning after failed operation
# losetup -d /dev/loop0
losetup: /dev/loop0: detach failed: No such file or directory
losetup: device node /dev/loop0 (7:0) is lost. You may use mknod(1) to recover it.
* fix copy & past bugs in some API comments
Co-Author: Karel Zak <kzak@redhat.com> Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 25 Oct 2023 09:37:21 +0000 (11:37 +0200)]
Merge branch 'refine-the-choice-of-stream-related-functions-in-usage' of https://github.com/masatake/util-linux
* 'refine-the-choice-of-stream-related-functions-in-usage' of https://github.com/masatake/util-linux:
Make the ways of using output stream consistent in usage()
Use fputs instead of fprintf if possible
Karel Zak [Mon, 23 Oct 2023 12:47:35 +0000 (14:47 +0200)]
libsmartcols: add wrap-zero test
* modify samples/fromfile.c to use scols_wrapzero_nextchunk() callback
if "wrapzero" specified for the test colum
* add col-wrapzero and data-string-zero to define the column and zero
separated data
Karel Zak [Mon, 23 Oct 2023 12:35:21 +0000 (14:35 +0200)]
libsmartcols: support \x?? for data by samples/fromfile.c
The test (sample) binary already supports \n in strings to covert it
to the real line-break. It seem more generic to use \x?? (hex) to
support arbitrary byte in the column data.