Commit Graph

13075 Commits

Author SHA1 Message Date
Karel Zak 7ca122ba84 include/list: add list_entry_is_first() and list_count_entries()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 3bb882be44 libsmartcols: split print.c into print.c, put.c and print-api.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 06a8decd72 libsmartcols: move width calculation to separate file
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak ecd7cd253d libsmartcols: rename table_print.c to print.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak ce6cb22f0d libsmartcols: move buffer stuff to buffer.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 6408e164e1 libsmartcols: add another UTF symbols
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 5d201da68f libsmartcols: add is_last_child(), move is_last_column()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 0986f29a3f lsblk: make devtree dependences more generic
We also need reference from child to parent to implement multi-parent
view. This change allows to walk on tree in both directions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 94d4c2dca4 docs: add lsblk --merge to TODO
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak dc4662f0e7 lsblk: add --dedup <column>
The target use-case are systems with large number of multi-path
devices or systems with duplicate (copied) filesystems.

The feature is flexible enough to use arbitrary column (for example
WWM or UUID, ...) as de-duplication key.

For example tree with multi-path devices sd{c,d,e,f}

./lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 223.6G  0 disk
├─sda1        8:1    0   200M  0 part  /boot/efi
├─sda2        8:2    0   200M  0 part  /boot
├─sda3        8:3    0 130.3G  0 part
├─sda4        8:4    0    50G  0 part  /
└─sda5        8:5    0  42.9G  0 part
sdb           8:16   0  74.5G  0 disk
└─sdb1        8:17   0  74.5G  0 part  /home/archive
sdc           8:32   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sdd           8:48   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sde           8:64   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part
sdf           8:80   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part

De-duplicate by WWN:

./lsblk -M WWN
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0 223.6G  0 disk
├─sda1        8:1    0   200M  0 part  /boot/efi
├─sda2        8:2    0   200M  0 part  /boot
├─sda3        8:3    0 130.3G  0 part
├─sda4        8:4    0    50G  0 part  /
└─sda5        8:5    0  42.9G  0 part
sdb           8:16   0  74.5G  0 disk
└─sdb1        8:17   0  74.5G  0 part  /home/archive
sdc           8:32   0   100M  0 disk
└─mpatha    253:0    0   100M  0 mpath
  ├─mpatha1 253:1    0    50M  0 part
  └─mpatha2 253:2    0    49M  0 part

Addresses: https://github.com/karelzak/util-linux/issues/616
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 10501add02 lsblk: remember whole-disk, remove unused struct member
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak d81e32bde9 lsblk: make device_get_data() more generic
* independent on smartcols line
* keep sort data optional

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 57a061339b lsblk: apply --nodeps to partitions too
The new implementation differentiates between partitions and another
dependences -- this is regression, we need root devices only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 8a2f175cbb lsblk: read queue/discard_granularity only when necessary
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 81a8936c56 lsblk: reuse 'removable' flag from parent
It's used in the default output, let's make it a little bit more
effective.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak ff7992d631 lsblk: don't keep sysfs dirs open
Don't keep open sysfs file descriptors for all time to avoid problems
on systems with huge number of block devices.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak c9ea91d41e lib/path: allow to close dirfd
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak b158bd29de lsblk: rename set_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak b93585e8fc lsblk: add comments
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak e7b5353e8b lsblk: add process_all_devices_inverse()
This is necessary to implement --inverse. Note that this new
implementation scans /sys/dev/block/ to get top-level devices
and than it calls process_one_device().

Note that standard non-inverse tree does not use process_one_device()
as it's more effective to scan /sys/block where are no partitions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:58 +01:00
Karel Zak 93c687d895 lib/sysfs: add function to detect partitioned devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak e15c9e3dc5 lsblk: reorder functions
The goal is to call process_one_device() from process_all_devices(),
so let's it keep in code in the right order.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak cf3c1bc77a lsblk: make process_partitions() more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 0e086f8230 lsblk: remove unncessary parent pointer
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak ae4c2c375b lsblk: use real rather than hardcoded parent
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 4ca3c472f3 lsblk: use devtree functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak e2d7870b00 lsblk: add lsblk_device_has_dependence()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 291606faf9 lsblk: process_one_device() refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 583b6489f6 lsblk: add devtree_get_device_or_new()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 97c89dff13 lsblk: keep functions names consistent
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 9b4c648612 lsblk: remove unused reset_device()
Now all is maintained by reference counting ion the devtree.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 57502dd34c lsblk: fix devtree deallocation
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak f43b829759 lsblk: split sysfs reading and scols table filling
This change allows read devices from sysfs only once and reuse device
properties if the device is references more than once in the tree
(RAIDs, etc.).

* every device is in the tree only once (tree->devices list)

* iterate_block_devices() reuse already read devices (for example if
  already read for any dependence)

* the smartscols table is build from the final tree

The patch temporary disables dependencies evaluation (in
process_blkdev() to keep the patch small and simple.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 21d4a48c9c lsblk: cleanup device reference in the tree
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 3bf2a36cc5 lsblk: remove badly named debug interface name
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 5bb395f4f6 lsblk: add basic function to build devices tree
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak a0a76f4265 lsblk: properly initialize structs
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 7cd9de40fa lsblk: rename reset_lsblk_device() to reset_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak fed34a1e63 lsblk: rename blkdev_cxt to lsblk_device
The patch does not change code logic and semantic -- just rename.

* set_cxt() to set_device()
* struct blkdev_cxt to lsblk_device

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:32:57 +01:00
Karel Zak 8229ed2f5c build-sys: do not require crypt()
The function is necessary only for newgrp and sulogin.

Addresses: https://github.com/karelzak/util-linux/issues/584
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Karel Zak a68ed87ffe build-sys: do not require dirfd()
The dirfd() is required on many places, but it should not be required for
all utils by ./configure.ac.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Karel Zak 3001923ba1 build-sys: improve error message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Karel Zak 6df5acf970 lib/timer: add fallback if timer_create() not available
* add struct ul_timer as API abstraction to hide differences between
timer_create() and setitimer()

* add setitimer() detection to ./configure.ac

* add fallback code to use setitimer() if timer_create() not available
  (for example on OSX)

Addresses: https://github.com/karelzak/util-linux/issues/584
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Karel Zak 9a558f9cf6 build-sys: make sure HAVE_TIMER_CREATE defined
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-03 11:23:33 +01:00
Ruediger Meier 1866fa6a59 include/c: re-add type checking in container_of()
This reverts parts of commit eb06d5d4, which seems to be based on
Linux kernel commit c7acec71. Unlike the original kernel patch we did
not add that even stronger type checking by using macro BUILD_BUG_ON_MSG.
So basically we removed a useful warning when compiling such
broken code:

      struct st {
            int a;
            char b;
      };
      struct st t = { .a = 1, .b = 2 };
      struct st *x = container_of(&t.a, struct st, b);
      printf("%p %p\n", (void *)&t, (void *)x);

Moreover we also introduced a new compiler warning for intel/icc:
   "arithmetic on pointer to void or function type"

Let's just revert the update of container_of() because adding a
kernel-like BUILD_BUG_ON_MSG would be too much noise and also
problematic (see kernel commit c03567a8). Also note that the original
problem addressed by the kernel commit seems to be only reproducible
with gcc 4.9, not with any later gcc nor clang,icc. Moreover, currently
we have no such use-case in the UL sources anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-12-03 10:29:56 +01:00
Karel Zak 0d79f5805f tests: make lsns-netnsid portable
It seems ip(8) link-show command does not provide link-netnsid in all
cases (versions ?). Let's try to use "ip netns list-id" as fallback.

This commit also add possibility to debug the script by $LOG variable.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 12:24:15 +01:00
Karel Zak 7174b93dfd tests: enlarge backing file for fstab-btrfs
It seems the new limit for Btrfs is 47MiB.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 12:22:48 +01:00
Karel Zak e11d0b8c88 lib/canonicalize: fix typo
Addresses: 8b8277b7a8 (commitcomment-31491031)
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00
Karel Zak df61216c67 libmount: (fuse) follow only user_id= on umount
The option user= is already handled by evaluate_permissions() and by
classic mount and umount usermount support. It seems we do not need
to duplicate support for user= in is_fuse_usermount().

The option user_id= is fuse specific and it's maintained by
libfuse/kernel in /proc/self/mountinfo. This is feature we need to
support in umount(8).

Addresses: https://github.com/karelzak/util-linux/pull/705
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00
Rian Hunter 5fea669e9e libmount: Support unmount FUSE mounts
FUSE mounts don't need an fstab entry to be unmounted.
This checks if a mount is a FUSE mount before checking for
the fstab entry, and if so returns success.

[kzak@redhat.com: - use libmount tools for mount options
                  - use namespace switches
                  - cleanup code

 The requirement is user=<username> or user_id=<uid> in /proc/self/mountinfo
 for fuse filesystem. The logic is the same as for user= mount options, but in
 this case it is not maintained by libmount in userspace, but by fuse FS in kernel.]

Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00