]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: downgrade ENOMEDIUM warnings 38313/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 24 Jul 2025 08:42:50 +0000 (10:42 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 24 Jul 2025 08:42:50 +0000 (10:42 +0200)
I noticed similar warnings in many VM boots:
  fedora (udev-worker)[475]: sr0: Failed to open device node: No medium found
This particular one is from src/udev/udev-builtin-uaccess.c:125, but I think the
same principle should be used in all places: if we are ignoring errors that the
device has been removed, we should also ignore ENOMEDIUM.

src/basic/errno-util.h
src/udev/ata_id/ata_id.c
src/udev/mtd_probe/mtd_probe.c
src/udev/udev-builtin-blkid.c
src/udev/udev-builtin-btrfs.c
src/udev/udev-builtin-keyboard.c
src/udev/udev-builtin-uaccess.c
src/udev/udev-node.c
src/udev/udev-worker.c
src/udev/v4l_id/v4l_id.c

index 05d416d7ae90041e8744b8a16ca360ac4a87f158..5fe337cfb1e48bb3bbbf8bb1a00eb319e52ec8c0 100644 (file)
@@ -212,6 +212,13 @@ static inline bool ERRNO_IS_NEG_DEVICE_ABSENT(intmax_t r) {
 }
 _DEFINE_ABS_WRAPPER(DEVICE_ABSENT);
 
+/* Device is absent or "empty". We get -ENOMEDIUM from CD/DVD devices, also in VMs. */
+static inline bool ERRNO_IS_NEG_DEVICE_ABSENT_OR_EMPTY(intmax_t r) {
+        return ERRNO_IS_NEG_DEVICE_ABSENT(r) ||
+                r == -ENOMEDIUM;
+}
+_DEFINE_ABS_WRAPPER(DEVICE_ABSENT_OR_EMPTY);
+
 /* Quite often we want to handle cases where the backing FS doesn't support extended attributes at all and
  * where it simply doesn't have the requested xattr the same way */
 static inline bool ERRNO_IS_NEG_XATTR_ABSENT(intmax_t r) {
index 6a3614acac0ea6edec95846aa067d382a3d57855..508f99b01a06a37febb485538024144e60897695 100644 (file)
@@ -413,7 +413,7 @@ static int run(int argc, char *argv[]) {
 
         fd = open(ASSERT_PTR(arg_device), O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
                 log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
                                "Failed to open device node '%s'%s: %m",
                                arg_device, ignore ? ", ignoring" : "");
index 5899f5ae9c593232533365cf584088ed1d948716..d79a0617e21e02f1cd2aca17c124ffad63ae7aa9 100644 (file)
@@ -75,7 +75,7 @@ static int run(int argc, char** argv) {
 
         mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (mtd_fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
                 log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
                                "Failed to open device node '%s'%s: %m",
                                argv[1], ignore ? ", ignoring" : "");
index c5d3e89c778f224ad70b2b60f583543545973e1a..1480efd743cdd1ae4f575017e562b3ae70e95e82 100644 (file)
@@ -499,7 +499,7 @@ static int builtin_blkid(UdevEvent *event, int argc, char *argv[]) {
 
         fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
                 log_device_debug_errno(dev, fd, "Failed to open block device %s%s: %m",
                                        devnode, ignore ? ", ignoring" : "");
                 return ignore ? 0 : fd;
index 4b5a5fc610eff1568a365b4eb46f7ae0f7a51598..c96d8e97322ca02dfe45653102344988edeeb699 100644 (file)
@@ -35,7 +35,7 @@ static int builtin_btrfs(UdevEvent *event, int argc, char *argv[]) {
 
         _cleanup_close_ int fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
-                if (ERRNO_IS_DEVICE_ABSENT(errno)) {
+                if (ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno)) {
                         /* Driver not installed? Then we aren't ready. This is useful in initrds that lack
                          * btrfs.ko. After the host transition (where btrfs.ko will hopefully become
                          * available) the device can be retriggered and will then be considered ready. */
index 93a20639b8f78ef2b8607b1eae31a14b609cca02..5ab40a35526d36561f3800ab76b042eb00fd38a2 100644 (file)
@@ -201,7 +201,7 @@ static int builtin_keyboard(UdevEvent *event, int argc, char *argv[]) {
                         if (fd < 0) {
                                 fd = sd_device_open(dev, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
                                 if (fd < 0) {
-                                        bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                                        bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
                                         log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
                                                               "Failed to open device '%s'%s: %m",
                                                               node, ignore ? ", ignoring" : "");
@@ -223,7 +223,7 @@ static int builtin_keyboard(UdevEvent *event, int argc, char *argv[]) {
                         if (fd < 0) {
                                 fd = sd_device_open(dev, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
                                 if (fd < 0) {
-                                        bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                                        bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
                                         log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
                                                               "Failed to open device '%s'%s: %m",
                                                               node, ignore ? ", ignoring" : "");
index 1f09ec36cd1ef71af61a57d443522cfd46b080b2..c382f957cfa4fbb20f5c4fce428f8078aabc6422 100644 (file)
@@ -122,7 +122,7 @@ static int builtin_uaccess(UdevEvent *event, int argc, char *argv[]) {
 
         _cleanup_close_ int fd = sd_device_open(dev, O_CLOEXEC|O_PATH);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
                 log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
                                       "Failed to open device node%s: %m",
                                       ignore ? ", ignoring" : "");
index 849de60177a5e2806bea19b1ab4ada8a1d3a0f6c..75e8b09e89f32da0e9f09641b8dbd601a1056afd 100644 (file)
@@ -431,7 +431,7 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
                 return r;
 
         r = node_get_current(slink, dirfd, &current_id, add ? &current_prio : NULL);
-        if (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))
+        if (r < 0 && !ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(r))
                 return log_device_debug_errno(dev, r, "Failed to get the current device node priority for '%s': %m", slink);
 
         r = stack_directory_update(dev, dirfd, add);
@@ -702,7 +702,7 @@ int udev_node_apply_permissions(
 
         node_fd = sd_device_open(dev, O_PATH|O_CLOEXEC);
         if (node_fd < 0) {
-                if (ERRNO_IS_DEVICE_ABSENT(node_fd)) {
+                if (ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(node_fd)) {
                         log_device_debug_errno(dev, node_fd, "Device node %s is missing, skipping handling.", devnode);
                         return 0; /* This is necessarily racey, so ignore missing the device */
                 }
@@ -735,7 +735,7 @@ int static_node_apply_permissions(
 
         node_fd = open(devnode, O_PATH|O_CLOEXEC);
         if (node_fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
                 log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
                                "Failed to open device node '%s'%s: %m",
                                devnode, ignore ? ", ignoring" : "");
index 2a7235589bbaf6c10d48095571739dc465de58de..c75947a0cbca3af63be7b37bf95cabadeb0eb925 100644 (file)
@@ -112,7 +112,7 @@ static int worker_lock_whole_disk(UdevWorker *worker, sd_device *dev, int *ret_f
 
         fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
 
                 log_device_debug_errno(dev, fd, "Failed to open '%s'%s: %m", whole_disk, ignore ? ", ignoring" : "");
                 if (!ignore)
@@ -178,7 +178,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) {
 
         _cleanup_close_ int fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
                 log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
                                       "Failed to open device node '%s'%s: %m",
                                       node, ignore ? ", ignoring" : "");
index cab1308d670cb345bc87fdc5f9b8dc20ff9ab185..1e374c393c347b54eb44a062b31efc139484bb67 100644 (file)
@@ -61,7 +61,7 @@ static int run(int argc, char *argv[]) {
 
         fd = open(arg_device, O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0) {
-                bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+                bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
                 log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
                                "Failed to open device node '%s'%s: %m",
                                arg_device, ignore ? ", ignoring" : "");