discover-image: restore compatibility with C9S and overlayfs directories

5817c73391 broke compatibility with
CentOS 9 and overlayfs directories, the following fails with -EOPTNOTSUPP:

mount -t overlay overlay -o lowerdir=/tmp/app1:/tmp/rootdir /tmp/overlay
portablectl attach --copy=symlink --now --runtime /tmp/overlay app1

name_to_handle_at() fails both with and without AT_HANDLE_MNT_ID_UNIQUE.

Restore the fallback to path_get_mnt_id_at() that was removed.
Fixes TEST-29-PORTABLE.directory

Follow-up for 5817c73391
This commit is contained in:
Luca Boccassi
2026-02-09 19:39:51 +00:00
parent 14519d7dfa
commit cd45d803c3
+19 -3
View File
@@ -455,10 +455,26 @@ static int image_make(
uint64_t on_mount_id;
int _mnt_id;
/* The fallback is required for CentOS 9 compatibility when working on a directory located on an
* overlayfs. */
r = name_to_handle_at_try_fid(fd, /* path= */ NULL, &fh, &_mnt_id, &on_mount_id, AT_EMPTY_PATH);
if (r < 0)
return r;
if (r == 0)
if (r < 0) {
if (is_name_to_handle_at_fatal_error(r))
return r;
r = path_get_unique_mnt_id_at(fd, /* path= */ NULL, &on_mount_id);
if (r < 0) {
if (!ERRNO_IS_NEG_NOT_SUPPORTED(r) && r != -EUNATCH)
return r;
int on_mount_id_fallback = -1;
r = path_get_mnt_id_at(fd, /* path= */ NULL, &on_mount_id_fallback);
if (r < 0)
return r;
on_mount_id = on_mount_id_fallback;
}
} else if (r == 0)
on_mount_id = _mnt_id;
if (S_ISDIR(st->st_mode)) {