From 951def0e276c041a262b3f147bb42206195fe13e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Feb 2025 09:20:51 +0900 Subject: [PATCH 1/3] udev-worker: add debugging log about success of flock() for whole block device --- src/udev/udev-worker.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/udev/udev-worker.c b/src/udev/udev-worker.c index 5c7583a9ff..b26bf3b980 100644 --- a/src/udev/udev-worker.c +++ b/src/udev/udev-worker.c @@ -124,6 +124,7 @@ static int worker_lock_whole_disk(sd_device *dev, int *ret_fd) { if (flock(fd, LOCK_SH|LOCK_NB) < 0) return log_device_debug_errno(dev, errno, "Failed to flock(%s): %m", val); + log_device_debug(dev, "Successfully took flock(LOCK_SH) for %s, it will be released after the event has been processed.", val); *ret_fd = TAKE_FD(fd); return 1; From a52aad3b4bb735a22ce67110142d135819589a87 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Feb 2025 09:22:49 +0900 Subject: [PATCH 2/3] udev-watch: mention that the failure is ignored --- src/udev/udev-watch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 1b8e2b8dbd..9bd34af858 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -167,7 +167,7 @@ finalize: /* 5. remove symlink ID -> wd. * The file is always owned by the device. Hence, it is safe to remove it unconditionally. */ if (unlinkat(dirfd, id, 0) < 0 && errno != ENOENT) - log_device_debug_errno(dev, errno, "Failed to remove '/run/udev/watch/%s': %m", id); + log_device_debug_errno(dev, errno, "Failed to remove '/run/udev/watch/%s', ignoring: %m", id); return r; } From b3b442062045eac61a9dd3ed73b650dfb5be0b46 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Feb 2025 09:23:33 +0900 Subject: [PATCH 3/3] udev-watch: do not try to remove invalid watch handle When a new device is processed, there should be no watch handle for the device, hence udev_watch_clear() provides -1. Let's not try to call inotify_rm_watch() in that case. This should not change any behavior. Just for suppressing spurious debugging log: ===== (udev-worker)[3626140]: zram1: Removing watch handle -1. ===== --- src/udev/udev-watch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 9bd34af858..82db39fecd 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -161,7 +161,7 @@ static int udev_watch_clear(sd_device *dev, int dirfd, int *ret_wd) { if (ret_wd) *ret_wd = wd; - r = 0; + r = 1; finalize: /* 5. remove symlink ID -> wd. @@ -249,7 +249,7 @@ int udev_watch_end(int inotify_fd, sd_device *dev) { /* First, clear symlinks. */ r = udev_watch_clear(dev, dirfd, &wd); - if (r < 0) + if (r <= 0) return r; /* Then, remove inotify watch. */