From efe3164e83da693f87e832c087797be8d466c306 Mon Sep 17 00:00:00 2001 From: Tony Rodriguez Date: Mon, 27 Feb 2023 19:30:00 +0100 Subject: Fix missing netdev for iscsi entry in fstab Orabug: 25897792 To check every entry of fstab whether it is iscsi and then set it to remote-fs.target on the corresponding ".mount' file. We use find_device() to find the corresponding device using the udev function. Signed-off-by: Tony Lam Signed-off-by: Alex Burmashev Signed-off-by: Darren Archibald Signed-off-by: Tony Rodriguez Reviewed-by: Laurence Rochfort Reviewed-by: Aleksandr Burmashev --- diff -Nur systemd-252.orig/meson.build systemd-252/meson.build --- systemd-252.orig/meson.build 2023-02-27 12:30:47.814831419 -0800 +++ systemd-252/meson.build 2023-02-27 12:30:41.084646203 -0800 @@ -2351,7 +2351,9 @@ exe = executable( 'systemd-fstab-generator', 'src/fstab-generator/fstab-generator.c', - include_directories : includes, + 'src/udev/udevadm-util.c', + 'src/libsystemd/sd-device/device-util.c', + include_directories : [includes, udev_includes], link_with : [libshared], install_rpath : rootpkglibdir, install : true, diff -Nur systemd-252.orig/src/fstab-generator/fstab-generator.c systemd-252/src/fstab-generator/fstab-generator.c --- systemd-252.orig/src/fstab-generator/fstab-generator.c 2023-02-27 15:36:14.629052661 -0800 +++ systemd-252/src/fstab-generator/fstab-generator.c 2023-02-27 18:21:13.382354633 -0800 @@ -32,6 +32,8 @@ #include "util.h" #include "virt.h" #include "volatile-util.h" +#include "device-util.h" +#include "udevadm-util.h" typedef enum MountPointFlags { MOUNT_NOAUTO = 1 << 0, @@ -735,6 +737,9 @@ k = add_swap(fstab, what, me, flags); else { bool rw_only, automount; + const char *name; + _cleanup_(sd_device_unrefp) sd_device *device = NULL; + int st; rw_only = fstab_test_option(me->mnt_opts, "x-systemd.rw-only\0"); automount = fstab_test_option(me->mnt_opts, @@ -749,6 +754,33 @@ mount_is_network(me) ? SPECIAL_REMOTE_FS_TARGET : SPECIAL_LOCAL_FS_TARGET; + if (target_unit && strcmp(target_unit, SPECIAL_LOCAL_FS_TARGET) == 0){ + st = find_device(what, NULL, &device); + if (st < 0 || !device) { + /* For local device, find_device() will always be successful. For iscsi, + during bootup time, find_device() may fail, so we set to REMOTE-FS + if find_device() failed */ + + target_unit = SPECIAL_REMOTE_FS_TARGET; + log_debug("set %s SPECIAL_REMOTE_FS_TARGET since device is NULL or find_device() return code is %d", what, st); + } + else { + log_debug("device found %s: %p", where, device); + + FOREACH_DEVICE_DEVLINK(device, name) { + if (name && strstr(name, "iscsi")) { + target_unit = SPECIAL_REMOTE_FS_TARGET; + log_debug("set %s SPECIAL_REMOTE_FS_TARGET ", what); + break; + } + } + + if (strcmp(target_unit, SPECIAL_LOCAL_FS_TARGET) == 0) + log_debug("set %s SPECIAL_LOCAL_FS_TARGET ", what); + } + } + + k = add_mount(fstab, arg_dest, what,