Skip to content

udev: do not skip events when device is already locked - #22717

Merged
poettering merged 8 commits into
systemd:mainfrom
yuwata:udev-lock-block-device-by-main-process
Mar 25, 2022
Merged

poettering merged 8 commits into
systemd:mainfrom
yuwata:udev-lock-block-device-by-main-process

Conversation

@yuwata

@yuwata yuwata commented Mar 12, 2022

Copy link
Copy Markdown
Member

No description provided.

@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from 8c4d199 to dd5d942 Compare March 12, 2022 08:50
@systemd systemd deleted a comment from lgtm-com Bot Mar 12, 2022
@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from dd5d942 to 97c044c Compare March 12, 2022 12:08
@yuwata yuwata changed the title [WIP] udev: lock block device by main process udev: lock block device by main process Mar 12, 2022
@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch 2 times, most recently from c60c8c5 to b078d7c Compare March 12, 2022 20:27
@yuwata

yuwata commented Mar 13, 2022

Copy link
Copy Markdown
Member Author

Now TEST-46-HOMED becomes quite unstable (but it was already unstable):

systemd-homework[1081]: Image file '/home/test-user.home' already locked, can't use.

But this is a lock for regular file, and should not be (at least directly) related to this PR. I guess there is a race or fd leak in homed or homework.

@poettering Could you take a look https://jenkins-systemd.apps.ocp.ci.centos.org/job/upstream-vagrant-archlinux/10518/artifact/systemd-centos-ci/artifacts_lbwk7s93/vagrant-logs.Pqn/vagrant-arch-testsuite.Orc/TEST-46-HOMED/system.journal ?

@yuwata

yuwata commented Mar 13, 2022 •

Copy link
Copy Markdown
Member Author

Added two commits:

This is now ready for review. PTAL.

@yuwata

yuwata commented Mar 13, 2022 •

Copy link
Copy Markdown
Member Author

I noticed https://systemd.io/BLOCK_DEVICE_LOCKING needs to be updated. If this is approved, then I will do.

It seems the whole story do not needs any updates. Only minor issue. See #22722.

@yuwata

yuwata commented Mar 13, 2022

Copy link
Copy Markdown
Member Author

@mrc0mmand Could you run TEST-64 repeatedly with this PR on an affected CI env?

@mrc0mmand

Copy link
Copy Markdown
Member

@mrc0mmand Could you run TEST-64 repeatedly with this PR on an affected CI env?

Sure, unleashed systemd/systemd-centos-ci#474 on this PR.

@yuwata

yuwata commented Mar 13, 2022

Copy link
Copy Markdown
Member Author

Hm, not only homed test, but the repart test becomes also unstable...

@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from 48ab9bd to bdd4bd8 Compare March 13, 2022 12:42
@yuwata

yuwata commented Mar 13, 2022

Copy link
Copy Markdown
Member Author

@mrc0mmand Thanks. Could you re-trigger the CI in systemd/systemd-centos-ci#474? I hope the last failure is solved or at least mitigated.

@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch 2 times, most recently from 46c5e6a to b867169 Compare March 14, 2022 07:11
@bluca bluca added the homed homed, homectl, pam_homed label Mar 14, 2022
@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from b867169 to a0d8b3b Compare March 14, 2022 13:19
@yuwata

yuwata commented Mar 14, 2022

Copy link
Copy Markdown
Member Author

I noticed sd-makefs and sd-growfs do not flock block device...

@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from a0d8b3b to 360c5f0 Compare March 14, 2022 13:36
Comment thread src/udev/udevd.c Resolved
Comment thread src/udev/udevd.c Resolved
Comment thread src/udev/udevd.c Resolved
Comment thread src/udev/udevd.c Resolved
Comment thread src/udev/udevd.c Resolved
yuwata and others added 5 commits March 25, 2022 10:28
…another process

Previously, if a block device is locked by another process, then the
corresponding worker skip to process the corresponding event, and does
not broadcast the uevent to libudev listners. This causes several issues:

- During a period of a device being locked by a process, if a user trigger
  an event with `udevadm trigger --settle`, then it never returned.

- When there is a delay between close and unlock in a process, then the
  synthesized events triggered by inotify may not be processed. This can
  happens easily by wrapping mkfs with flock. This causes severe issues
  e.g. new devlinks are not created, or old devlinks are not removed.

This commit makes events are requeued with a tiny delay when the corresponding
block devices are locked by other processes. With this way, the triggered
uevent may be delayed but is always processed by udevd. Hence, the above
issues can be solved. Also, it is not necessary to watch a block device
unconditionally when it is already locked. Hence, the logic is dropped.
This also makes return value initialized when these function return 0 to
follow our coding style.

Just a preparation for later commits.
Then, hopefully, previously requeued events are processed earlier.
As stated in systemd#21819 (comment)
`mkfs.btrfs` doesn't hold the lock for the whole duration of
`mkfs.btrfs`, thus causing unexpected races & test fails. Let's
wrap the `mkfs.btrfs` calls in an flock wrapper to mitigate this.

Hopefully fixes: systemd#21819
@yuwata
yuwata force-pushed the udev-lock-block-device-by-main-process branch from c4492b6 to 41d1aae Compare March 25, 2022 01:28
@poettering
poettering merged commit 6fb57ab into systemd:main Mar 25, 2022
@yuwata
yuwata deleted the udev-lock-block-device-by-main-process branch March 25, 2022 10:15
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 25, 2022
So, libudev listners can easily detect errors.

Addresses systemd#22717 (comment).
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 25, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 25, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 27, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 27, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 28, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 28, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
So, libudev listners can easily detect errors.

Addresses systemd#22717 (comment).
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
So, libudev listners can easily detect errors.

Addresses systemd#22717 (comment).
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
So, libudev listners can easily detect errors.

Addresses systemd#22717 (comment).
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 29, 2022
So, libudev listners can easily detect errors.

Addresses systemd#22717 (comment).
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 30, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 30, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Mar 31, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
yuwata added a commit to yuwata/systemd that referenced this pull request Apr 1, 2022
Prompted by systemd#22717 (comment).

The new command 'udevadm wait' waits for device or device symlink being
created. This may be useful to wait for a device is processed by udevd
after e.g. formatting or partitioning the device.
dtardon pushed a commit to dtardon/systemd-rhel9 that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

TEST-64-UDEV-STORAGE intermittent fails tracker

6 participants