Skip to content

Use libmount in systemd-shutdown, add tests#8452

Merged
poettering merged 6 commits intosystemd:masterfrom
keszybz:use-libmount-more
Mar 20, 2018
Merged

Use libmount in systemd-shutdown, add tests#8452
poettering merged 6 commits intosystemd:masterfrom
keszybz:use-libmount-more

Conversation

@keszybz
Copy link
Member

@keszybz keszybz commented Mar 14, 2018

No description provided.

This one might actually might cause a crash.
Copy link
Contributor

@medhefgo medhefgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay. Moar homebrew parsing eliminated.


m = new0(MountPoint, 1);
if (!m)
return -ENOMEM;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the cunescape call you log_oom().

@hphilm hphilm mentioned this pull request Mar 14, 2018
@hphilm
Copy link

hphilm commented Mar 15, 2018

@keszybz: this seems to avoid the crashes some of my users reported, however, there is still some off like:

systemd-cryptsetup[2521]: Failed to deactivate: Device or resource busy
systemd[1]: [email protected]: Control process exited, code=exited status=1
systemd[1]: [email protected]: Failed with result 'exit-code'.

... which affects mounts in /etc/crypttab.

@Th3Z0ne
Copy link

Th3Z0ne commented Mar 15, 2018

As requested by @philmmanjaro, I am adding my information of my system which has one encrypted/and does not use /etc/crypttab to mount any additional encrypted partitions and thus is not effected.

Successfull shutdown without any errors:

Mär 14 21:16:50 hk-01 systemd[1]: Stopped Load/Save Screen Backlight Brightness of leds:tpacp>
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Load/Save Random Seed.
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Update UTMP about System Boot/Shutdown.
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Load/Save Screen Backlight Brightness of backlight:>
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Create Volatile Files and Directories.
Mär 14 21:16:50 hk-01 systemd[1]: Stopped target Local File Systems.
Mär 14 21:16:50 hk-01 systemd[1]: Unmounting Temporary Directory (/tmp)...
Mär 14 21:16:50 hk-01 systemd[1]: Unmounting /run/user/1000...
Mär 14 21:16:50 hk-01 systemd[1]: Unmounting /boot/efi...
Mär 14 21:16:50 hk-01 systemd[1]: Removed slice system-systemd\x2dbacklight.slice.
Mär 14 21:16:50 hk-01 systemd[1]: Unmounted /run/user/1000.
Mär 14 21:16:50 hk-01 systemd[1]: Unmounted /boot/efi.
Mär 14 21:16:50 hk-01 systemd[1]: Stopped target Local File Systems (Pre).
Mär 14 21:16:50 hk-01 systemd[1]: Stopping Monitoring of LVM2 mirrors, snapshots etc. using d>
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Create Static Device Nodes in /dev.
Mär 14 21:16:50 hk-01 systemd[1]: Unmounted Temporary Directory (/tmp).
Mär 14 21:16:50 hk-01 systemd[1]: Stopped target Swap.
Mär 14 21:16:50 hk-01 systemd[1]: Deactivating swap /swapfile...
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Monitoring of LVM2 mirrors, snapshots etc. using dm>
Mär 14 21:16:50 hk-01 systemd[1]: Stopping LVM2 metadata daemon...
Mär 14 21:16:50 hk-01 systemd[1]: Stopped LVM2 metadata daemon.
Mär 14 21:16:50 hk-01 systemd[1]: Deactivated swap /swapfile.
Mär 14 21:16:50 hk-01 systemd[1]: Reached target Unmount All Filesystems.
Mär 14 21:16:50 hk-01 systemd[1]: Stopped Remount Root and Kernel File Systems.
Mär 14 21:16:50 hk-01 systemd[1]: Reached target Shutdown.
Mär 14 21:16:50 hk-01 systemd[1]: Reached target Final Step.
Mär 14 21:16:50 hk-01 systemd[1]: Starting Reboot...
Mär 14 21:16:50 hk-01 systemd[1]: Shutting down.
Mär 14 21:16:50 hk-01 systemd[1]: Hardware watchdog 'iTCO_wdt', version 0
Mär 14 21:16:50 hk-01 systemd[1]: Set hardware watchdog to 10min.
Mär 14 21:16:50 hk-01 kernel: watchdog: watchdog0: watchdog did not stop!
Mär 14 21:16:50 hk-01 kernel: systemd-shutdow: 33 output lines suppressed due to ratelimiting
Mär 14 21:16:50 hk-01 systemd-shutdown[1]: Syncing filesystems and block devices.
Mär 14 21:16:50 hk-01 systemd-shutdown[1]: Sending SIGTERM to remaining processes...
Mär 14 21:16:50 hk-01 systemd-journald[320]: Journal stopped
~
Drives:    HDD Total Size: 500.1GB (30.7% used)
           ID-1: /dev/sda model: Samsung_SSD_850 size: 500.1GB
Partition: ID-1: / size: 457G used: 144G (34%) fs: ext4 dev: /dev/dm-0

/etc/crypttab i need not post as it isn't populated except for the default comments explaining how it works.

@medhefgo
Copy link
Contributor

@philmmanjaro Those look unrelated to me. Not that those log lines don't come from sd-shutdown.

@Th3Z0ne Please boot with "printk.devkmsg=on loglevel=7" for full logs.

@xabbu
Copy link

xabbu commented Mar 15, 2018

The lines @philmmanjaro posted are from my system. crypttab contains two devices, both with options "luks,timeout=180"

This is a more complete excerpt.

Mär 15 16:50:40 Home systemd[1199]: Reached target Shutdown.
Mär 15 16:50:40 Home systemd[1199]: Starting Exit the Session...
Mär 15 16:50:40 Home systemd[1199]: Received SIGRTMIN+24 from PID 6127 (kill).
Mär 15 16:50:40 Home systemd[1]: Stopped User Manager for UID 1000.
Mär 15 16:50:40 Home systemd[1]: Removed slice User Slice of xabbu.
Mär 15 16:50:40 Home systemd[1]: Stopping Permit User Sessions...
Mär 15 16:50:40 Home systemd[1]: Stopping Login Service...
Mär 15 16:50:40 Home systemd[1]: Stopped Permit User Sessions.
Mär 15 16:50:40 Home systemd[1]: Stopped target Network.
Mär 15 16:50:40 Home systemd[1]: Stopping Network Manager...
Mär 15 16:50:40 Home systemd[1]: Stopped target Remote File Systems.
Mär 15 16:50:40 Home NetworkManager[748]: <info>  [1521129040.6911] caught SIGTERM, shutting down normally.
Mär 15 16:50:40 Home NetworkManager[748]: <info>  [1521129040.7727] exiting (success)
Mär 15 16:50:40 Home systemd[1]: Stopped Network Manager.
Mär 15 16:50:40 Home systemd[1]: Stopping D-Bus System Message Bus...
Mär 15 16:50:40 Home systemd[1]: Stopped D-Bus System Message Bus.
Mär 15 16:50:40 Home systemd[1]: Stopped Login Service.
Mär 15 16:50:40 Home systemd[1]: Stopped target User and Group Name Lookups.
Mär 15 16:50:40 Home systemd[1]: Stopped target Basic System.
Mär 15 16:50:40 Home systemd[1]: Stopped target Slices.
Mär 15 16:50:40 Home systemd[1]: Stopped target Sockets.
Mär 15 16:50:40 Home systemd[1]: Closed Avahi mDNS/DNS-SD Stack Activation Socket.
Mär 15 16:50:40 Home systemd[1]: Closed D-Bus System Message Bus Socket.
Mär 15 16:50:40 Home systemd[1]: Closed CUPS Scheduler.
Mär 15 16:50:40 Home systemd[1]: Stopped target Paths.
Mär 15 16:50:40 Home systemd[1]: Stopped CUPS Scheduler.
Mär 15 16:50:40 Home systemd[1]: Stopped target System Initialization.
Mär 15 16:50:40 Home systemd[1]: Stopped Update is Completed.
Mär 15 16:50:40 Home systemd[1]: Stopping Update UTMP about System Boot/Shutdown...
Mär 15 16:50:40 Home systemd[1]: Stopped Rebuild Journal Catalog.
Mär 15 16:50:40 Home systemd[1]: Stopped target Local Encrypted Volumes.
Mär 15 16:50:40 Home systemd[1]: Stopped Forward Password Requests to Wall Directory Watch.
Mär 15 16:50:40 Home systemd[1]: Stopping Cryptography Setup for Data...
Mär 15 16:50:40 Home systemd[1]: Stopping Cryptography Setup for Multimedia...
Mär 15 16:50:40 Home systemd[1]: Stopped Apply Kernel Variables.
Mär 15 16:50:40 Home systemd[1]: Stopped Load Kernel Modules.
Mär 15 16:50:40 Home systemd[1]: Stopped Rebuild Hardware Database.
Mär 15 16:50:40 Home systemd[1]: Stopped Rebuild Dynamic Linker Cache.
Mär 15 16:50:40 Home systemd[1]: Stopped Set Up Additional Binary Formats.
Mär 15 16:50:40 Home systemd[1]: Stopping Load/Save Random Seed...
Mär 15 16:50:40 Home systemd[1]: Stopping Network Time Synchronization...
Mär 15 16:50:40 Home systemd[1]: Stopped Dispatch Password Requests to Console Directory Watch.
Mär 15 16:50:40 Home systemd[1]: Removed slice User and Session Slice.
Mär 15 16:50:40 Home systemd[1]: Stopped Update UTMP about System Boot/Shutdown.
Mär 15 16:50:40 Home systemd[1]: Stopped Network Time Synchronization.
Mär 15 16:50:40 Home systemd[1]: Stopped Create Volatile Files and Directories.
Mär 15 16:50:40 Home systemd[1]: Stopped target Local File Systems.
Mär 15 16:50:40 Home systemd[1]: Unmounting /run/user/1000...
Mär 15 16:50:40 Home systemd[1]: Unmounting /scratch...
Mär 15 16:50:40 Home systemd[1]: Unmounting /boot/efi...
Mär 15 16:50:40 Home systemd[1]: Unmounting Temporary Directory (/tmp)...
Mär 15 16:50:40 Home systemd[1]: Stopped Load/Save Random Seed.
Mär 15 16:50:40 Home systemd-cryptsetup[6134]: Failed to deactivate: Device or resource busy
Mär 15 16:50:40 Home systemd[1]: [email protected]: Control process exited, code=exited status=1
Mär 15 16:50:40 Home systemd[1]: [email protected]: Failed with result 'exit-code'.
Mär 15 16:50:40 Home systemd[1]: Stopped Cryptography Setup for Multimedia.
Mär 15 16:50:40 Home systemd[1]: Unmounted /run/user/1000.
Mär 15 16:50:40 Home systemd-cryptsetup[6132]: Failed to deactivate: Device or resource busy
Mär 15 16:50:40 Home systemd[1]: Unmounted /scratch.
Mär 15 16:50:40 Home systemd[1]: [email protected]: Control process exited, code=exited status=1
Mär 15 16:50:40 Home systemd[1]: [email protected]: Failed with result 'exit-code'.
Mär 15 16:50:40 Home systemd[1]: Stopped Cryptography Setup for Data.
Mär 15 16:50:40 Home systemd[1]: Unmounted Temporary Directory (/tmp).
Mär 15 16:50:40 Home systemd[1]: Stopped target Swap.
Mär 15 16:50:40 Home systemd[1]: Deactivating swap /swapfile...
Mär 15 16:50:40 Home systemd[1]: Unmounted /boot/efi.
Mär 15 16:50:40 Home systemd[1]: Unmounting /boot...
Mär 15 16:50:40 Home systemd[1]: Deactivated swap /swapfile.
Mär 15 16:50:40 Home systemd[1]: Unmounted /boot.
Mär 15 16:50:40 Home systemd[1]: Unmounting /home/xabbu/Multimedia/Data...
Mär 15 16:50:41 Home systemd[1]: Unmounted /home/xabbu/Multimedia/Data.
Mär 15 16:50:41 Home systemd[1]: Stopped File System Check on /dev/mapper/Data.
Mär 15 16:50:41 Home systemd[1]: Unmounting /home/xabbu/Multimedia...
Mär 15 16:50:41 Home systemd[1]: Unmounted /home/xabbu/Multimedia.
Mär 15 16:50:41 Home systemd[1]: Reached target Unmount All Filesystems.
Mär 15 16:50:41 Home systemd[1]: Removed slice system-systemd\x2dcryptsetup.slice.
Mär 15 16:50:41 Home systemd[1]: Stopped File System Check on /dev/mapper/Multimedia.
Mär 15 16:50:41 Home systemd[1]: Removed slice system-systemd\x2dfsck.slice.
Mär 15 16:50:41 Home systemd[1]: Stopped target Local File Systems (Pre).
Mär 15 16:50:41 Home systemd[1]: Stopped Create Static Device Nodes in /dev.
Mär 15 16:50:41 Home systemd[1]: Stopped Create System Users.
Mär 15 16:50:41 Home systemd[1]: Stopped Remount Root and Kernel File Systems.
Mär 15 16:50:41 Home systemd[1]: Reached target Shutdown.
Mär 15 16:50:41 Home systemd[1]: Reached target Final Step.
Mär 15 16:50:41 Home systemd[1]: Starting Power-Off...
Mär 15 16:50:41 Home systemd[1]: Shutting down.
Mär 15 16:50:41 Home systemd-shutdown[1]: Syncing filesystems and block devices.
Mär 15 16:50:41 Home systemd-shutdown[1]: Sending SIGTERM to remaining processes...
Mär 15 16:50:41 Home systemd-journald[329]: Journal stopped

@medhefgo
Copy link
Contributor

Once again, those are unrelated to this (or my) pull request.

keszybz added 5 commits March 16, 2018 10:09
This is analogous to 8d3ae2b, except that now
src/core/umount.c not src/core/mount.c is converted.

Might help with https://bugzilla.redhat.com/show_bug.cgi?id=1554943, or not.

In the patch, mnt_free_tablep and mnt_free_iterp are declared twice. It'd
be nicer to define them just once in mount-setup.h, but then libmount.h would
have to be included there. libmount.h seems to be buggy, and declares some
defines which break other headers, and working around this is more pain than
the two duplicate lines. So let's live with the duplication for now.

This fixes memleak of MountPoint in mount_points_list_get() on error, not that
it matters any.
The implementation seems buggy:
/* test_swap_list("/home/zbyszek/src/systemd/test/test-umount/example.swaps") */
path=0 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile2 o= f=0x0 try-ro=no dev=0:0
path=/some/swapfile o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
example.swaps with "(deleted)" does not cause bogus entries in the list now,
but a memleak in libmount instead. The memleaks is not very important since
this code is run just once.
Reported as util-linux/util-linux#596.

$ build/test-umount
...
/* test_swap_list("/proc/swaps") */
path=/var/tmp/swap o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
/* test_swap_list("/home/zbyszek/src/systemd/test/test-umount/example.swaps") */
path=/some/swapfile o= f=0x0 try-ro=no dev=0:0
path=/dev/dm-2 o= f=0x0 try-ro=no dev=0:0
==26912==
==26912== HEAP SUMMARY:
==26912==     in use at exit: 16 bytes in 1 blocks
==26912==   total heap usage: 1,546 allocs, 1,545 frees, 149,008 bytes allocated
==26912==
==26912== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1
==26912==    at 0x4C31C15: realloc (vg_replace_malloc.c:785)
==26912==    by 0x55C5D8C: _IO_vfscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x55D8AEC: vsscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x55D25C3: sscanf (in /usr/lib64/libc-2.26.so)
==26912==    by 0x53236D0: mnt_table_parse_stream (in /usr/lib64/libmount.so.1.1.0)
==26912==    by 0x53249B6: mnt_table_parse_file (in /usr/lib64/libmount.so.1.1.0)
==26912==    by 0x10D157: swap_list_get (umount.c:194)
==26912==    by 0x10B06E: test_swap_list (test-umount.c:34)
==26912==    by 0x10B24B: main (test-umount.c:56)
==26912==
==26912== LEAK SUMMARY:
==26912==    definitely lost: 16 bytes in 1 blocks
==26912==    indirectly lost: 0 bytes in 0 blocks
==26912==      possibly lost: 0 bytes in 0 blocks
==26912==    still reachable: 0 bytes in 0 blocks
==26912==         suppressed: 0 bytes in 0 blocks
@keszybz keszybz force-pushed the use-libmount-more branch from c15310c to 71ae04c Compare March 16, 2018 09:13
@keszybz
Copy link
Member Author

keszybz commented Mar 16, 2018

Update with just one change: return -ENOMEMreturn log_oom().

@philmmanjaro, @Th3Z0ne, @xabbu those remaining errors at shutdown, are they new with #8429 or the patches in this PR, or did they exist before?

@hphilm
Copy link

hphilm commented Mar 16, 2018

@keszybz: according to @xabbu those errors got introduced by adopting cryptsetup v2.0 series. Building the current source against v1.7.5 removes those errors. So we have to see if cryptsetup itself or something in systemd should be modified/changed in that regard. However, this is not related to your current pull and work.

@keszybz
Copy link
Member Author

keszybz commented Mar 16, 2018

Hmm, I see this error in my shutdown log too. Please open a new issue so we can gather all the info.

@keszybz
Copy link
Member Author

keszybz commented Mar 20, 2018

#8472 is about the cryptsetup-related failures.

#include <sys/swap.h>

/* This needs to be after sys/mount.h :( */
#include <libmount.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karelzak hey, karel, this seems buggy in libmount.h!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooops, fixed -- the change will be in util-liux >= 2.32-rc2. Thanks for your report!

Copy link
Contributor

@karelzak karelzak Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch karelzak@eb50b6d clean ups the includes to avoid collision between sys/mount.h (or libmount.h) and linux/fs.h. Works for me. See also #8507.

#include "virt.h"

DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add libmount-util.h for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait until the situation with libmount.h is cleared.

r = cunescape(path, UNESCAPE_RELAX, &p);
if (r < 0)
return r;
if (cunescape(path, UNESCAPE_RELAX, &p) < 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libmount doesn't do the unescaping on its own? it really should, @karelzak!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urks, then this patch is borked (and most likely some other code like it we already have elsewhere)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I see unnecessary unescape() also in src/core/umount.c

@poettering
Copy link
Member

lgtm

@poettering poettering added the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Mar 20, 2018
@keszybz
Copy link
Member Author

keszybz commented Mar 20, 2018

@poettering it's been building for 4 days... waiting-for-ci doesn't make much sense.

@poettering poettering merged commit 8c637fe into systemd:master Mar 20, 2018
karelzak added a commit to util-linux/util-linux that referenced this pull request Mar 20, 2018
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.

Addresses: systemd/systemd#8452
Reported-by: Lennart Poettering <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
karelzak added a commit to util-linux/util-linux that referenced this pull request Mar 20, 2018
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.

Addresses: systemd/systemd#8452
Reported-by: Lennart Poettering <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
@keszybz keszybz deleted the use-libmount-more branch March 21, 2018 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed pid1 tests

Development

Successfully merging this pull request may close these issues.

7 participants