[systemd-devel] Masking mount units

Dan Nicholson dbn at endlessos.org
Tue Oct 29 15:16:12 UTC 2024


On Tue, Oct 29, 2024 at 6:28 AM Phillip Susi <phill at thesusis.net> wrote:
>
> So if you want to prevent automounting entirely you have to... open the
> disk device read only and take the bsd lock, and hold it until after
> closing the write file descriptor?  Plus probably a little more time to
> give udev a chance to try and fail to take the lock?

It sounds like parted is already opening the device writable in order
to issue ioctls.
If so, the pattern is, open, flock exclusive, do whatever you need,
close. The lock
is implicitly dropped when the file descriptor is closed. When the
file descriptor is
closed, udev will receive an inotify event and probe the device again.
I don't know
why you'd want to wait for udev to try and fail to take the lock.

> Then again, this will also prevent the udevdb from being updated.  Maybe
> that is a bigger hammer than you really want when the goal is just to
> stop auto mounting?

You started this by saying that you wanted to prevent udev from
probing the device,
which is exactly what will happen if you take an exclusive lock. Regardless of
automounting, this sounds like exactly what parted would want to ensure it has
exclusive access to the device while it potentially makes partition
table changes.
While changes are being made that cause change events, udev will be prevented
from probing the device since it can't obtain a shared lock. Once
parted closes the
device, udev will immediately reprobe the device and everyone will see
the updated
attributes. Sounds like a good scheme to me.

---
Dan


More information about the systemd-devel mailing list