Dusty Mabe [Tue, 13 Oct 2020 15:26:16 +0000 (11:26 -0400)]
fstrim: remove fstab condition from fstrim.timer
In 9995da0 we added support to fstrim to be able to fall back to
`/proc/self/mountinfo` if `/etc/fstab` didn't exist, but we forgot
to remove the `/etc/fstab` condition from the timer. Let's remove
that condition from the timer so we can go back to periodically
running `fstrim.service`.
Karel Zak [Tue, 13 Oct 2020 08:31:42 +0000 (10:31 +0200)]
losetup: avoid infinite busy loop
issue report:
if i run the heavy duty test from #16859 a couple of times I can get
the loopback layer in the kernel into a state where there's a loopback
block device allocated, that you can open, but where both LOOP_CLR_FD
and _SET_FD fail with EBUSY. and /dev/loop-control still returns it as
the next free one... weird state util-linux losetup when called to
allocate a new device then freezes
This commit:
* restrict number of attempts to 16
* use 200000ms sleep between attempts
* add note about non-atomic loop device setup to the man page
Reported-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 6 Oct 2020 11:26:36 +0000 (13:26 +0200)]
build-sys: exclude GPL from libcommon
The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.
Addresses: https://github.com/karelzak/util-linux/issues/1157 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 6 Oct 2020 11:15:29 +0000 (13:15 +0200)]
lib/procutils: use Public Domain for this file
It's was originally GPL, but all the current code in the file is from
me and I don't think it makes sense to use GPL here anymore. We need
to use lib/ files in LGPL as well as in GPL binaries, etc. Let's makes
things (build-system) less complicated.
Karel Zak [Thu, 1 Oct 2020 12:04:21 +0000 (14:04 +0200)]
login: use mem2strcpy() rather than rely on printf()
The strings from utmp does not have to be terminated. It's seems
better to explicitly terminate it than rely on "%.*s" printf()
functionality -- printf() man page assumes that "If a precision is
given, no null byte need be present", but static analyzers are pretty
unhappy with it.
Karel Zak [Wed, 30 Sep 2020 11:47:35 +0000 (13:47 +0200)]
col: enable deallocation on exit also for __SANITIZE_ADDRESS__
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.
Addresses: https://github.com/karelzak/util-linux/pull/1115 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 11:11:01 +0000 (13:11 +0200)]
libblkid: (gpt) accept tiny devices
GPT prober reads 2 first sectors. There is no overhead as we already
read begin of the device for another filesystems (like FAT) and we
have these sectors already in memory.
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 10:38:59 +0000 (12:38 +0200)]
libfdisk: (gpt) reduce number of entries to fit small device
The default is 128 partitions (entries in partitions array). The size
of the entry is 128 bytes, it means 32 sectors (512-byte) for the
array. The default is too large for tiny devices and it seems better to
dynamically reduce the number to fix the device size.
The reduction is reported to user.
Example:
$ dd if=/dev/zero of=8-sectors.img count=8 bs=512
$ fdisk 8-sectors.img
...
Command (m for help): g
Created a new GPT disklabel (GUID: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2).
The maximal number of partitions is 8 (default is 128).
Command (m for help): x
Expert command (m for help): p
Disk 8-sectors.img: 4 KiB, 4096 bytes, 8 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2
First LBA: 4
Last LBA: 4
Alternative LBA: 7
Partition entries LBA: 2
Allocated partition entries: 8
In this case, sectors:
0 - PMBR
1 - GPT header
2-3 - GPT array of partitions (8 entries, 128 bytes each)
4 - partition data
5-6 - backup GPT array of partitions
7 - backup GPT header
The smallest image is 6 sectors with 4 entries in array of partitions.
Note that Linux kernel has no problem to accept 4K image with 1
512-bytes GPT partition.
# losetup -P -f 4K.img
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 4K 0 loop
└─loop0p1 259:5 0 512B 0 part
... but we need to fix libblkid, it ignores so small devices to probe for GPT :)
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 30 Sep 2020 09:44:03 +0000 (11:44 +0200)]
libfdisk: (gpt) make sure device is large enough
The current code creates GPT header and partitions arrays (with 128
entries ...) although there is no space for all the stuff. This patch
forces fdisk_create_disklabel() to return -ENOSPC if the last and first
usable LBA calculation is out of device size.
Addresses: https://github.com/karelzak/util-linux/issues/1147 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Tue, 29 Sep 2020 11:41:00 +0000 (13:41 +0200)]
Merge branch 'col-refactor' of https://github.com/kerolasa/util-linux
* 'col-refactor' of https://github.com/kerolasa/util-linux:
col: replace LINE and CHAR typedefs with structs
col: free memory before exit [LeakSanitizer]
col: tidy up sources a little bit
col: add defaults to switch case clauses
col: flip all comparisions to numerical order
col: use size_t when dealing with numbers that buffer sizes
col: add structure to hold line variables
col: add update_cur_line() function
col: add handle_not_graphic() function
col: initialize variables when they are declared
col: move option handling to separate function
col: move global variables to a control structure
col: use inline function rather than function like define
col: use typedef and enum to clarify struct
col: remove function prototypes
col: add more tests
ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details). If SMBIOS Type 4 is present, use it to extract these strings.
Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:
[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium
Model: 1
Model name: ThunderX2 99xx
Stepping: 0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID: Cavium Inc.
Model: 1
Model name: Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping: 0x1
[kzak@redhat.com: - move dmi_header to lscpu.h
- make arm_cpu_smbios() more robust for failed
open() and read()
- use original arm_cpu_decode() also on failed
arm_cpu_smbios()]
Signed-off-by: Jeffrey Bastian <jbastian@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Fri, 25 Sep 2020 15:23:18 +0000 (17:23 +0200)]
libmount: improve mnt_split_optstr() performance
This function is used by fstab (etc.) parser to split VFS, FS and
userspace options to separate lists. Unfortunately, the current
implementation reallocates the final string always when append a new
option to the string.
The new implementation pre-allocate memory for the final string
according to source string length (1/2 of the original string). This
dramatically reduces realloc() calls.
For example oss-fuzz (./test_mount_fuzz) uses 800K input string, old
version needs 28s to parse the string, new version 500ms.
Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861 Signed-off-by: Karel Zak <kzak@redhat.com>
Gero Treuner [Thu, 10 Sep 2020 19:43:03 +0000 (21:43 +0200)]
fallocate: fix --dig-holes at end of files
I discovered that making a file sparse with "fallocate -d filename"
fails on the last block of a file, because - usually being partial -
the system call only zeroes that part instead of deallocating the
block. See man fallocate(2) - section "Deallocating file space".
The expected call is punching the whole block beyond eof, which
doesn't change the file length because of flag FALLOC_FL_KEEP_SIZE.
Sami Kerola [Sat, 12 Sep 2020 18:18:36 +0000 (19:18 +0100)]
col: replace LINE and CHAR typedefs with structs
Karel Zak said; typedef is evil, see reference. I don't know are they evil,
but it is fair comment structs without hiding what is the data type is
easier and quicker understand when reading the code.
Reference: https://github.com/karelzak/util-linux/pull/1115#discussion_r481971317 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Karel Zak [Wed, 9 Sep 2020 13:37:27 +0000 (15:37 +0200)]
mkswap: improve extents check
- remove unknown extent type (kernel does not care about it too)
- fix last_logical use in messages
- improve warning for DELALLOC extents
- check for hole at the end of the file
Reported-by: Lukas Czerner <lczerner@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 9 Sep 2020 10:18:07 +0000 (12:18 +0200)]
lsblk: ignore only loopdevs without backing file
* do not ignore all empty devices, we need more smart solution
* ignore only loop devices without backing file, for example:
# touch img
# losetup -f img
losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.
- old version display nothing
- new version:
# lsblk /dev/loop0
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 0B 0 loop
Addresses: https://github.com/karelzak/util-linux/issues/1118 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Wed, 9 Sep 2020 09:00:40 +0000 (11:00 +0200)]
mkswap: check for holes and unwanted extentd in file
Let's make mkswap(8) more user-friend and report possible swapon
issues already when user initialize a swap file. The extents check
produces warnings, no exit with error.
tests: mkfs-endianness test uses prepared test data
Commit 7b54f05d6b7124c23bff3bc1b8310231c8a2e131 added iflag=fullblock
option, it works fine with coreutils's dd but macOS's dd doesn't support
iflag option then test failed on macOS[1].
This commit added prepared test data for test to not use dd command to
avoid dd command difference.
tested on raspberry pi3
$ sudo sh -c 'for i in $(seq 1 500); do taskset -c 0 ./ts/cramfs/mkfs-endianness ; done' | grep FAILED | wc -l
0
tested on macOS
$ sudo sh -c 'for i in $(seq 1 500); do ./ts/cramfs/mkfs-endianness ; done' | grep FAILED | wc -l
0