From a89690f719bbd03d18ca171139f28125eb29ebc6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 Jun 2024 12:35:29 +0200 Subject: [PATCH] mountpoint-util: make is_name_to_handle_at_fatal_error() an exported API And while we are at it, make it use ERRNO_IS_xyz() where appropriate. And move it up a bit, so we can use in the whole of mountpoint-util.c (which we want to later). --- src/basic/mountpoint-util.c | 31 ++++++++++++++++++------------- src/basic/mountpoint-util.h | 2 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index de15ac73ca3..73b582f58f3 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -35,6 +35,24 @@ * with large file handles anyway. */ #define ORIGINAL_MAX_HANDLE_SZ 128 +bool is_name_to_handle_at_fatal_error(int err) { + /* name_to_handle_at() can return "acceptable" errors that are due to the context. For example the + * kernel does not support name_to_handle_at() at all (ENOSYS), or the syscall was blocked + * (EACCES/EPERM; maybe through seccomp, because we are running inside of a container), or the mount + * point is not triggered yet (EOVERFLOW, think autofs+nfs4), or some general name_to_handle_at() + * flakiness (EINVAL). However other errors are not supposed to happen and therefore are considered + * fatal ones. */ + + assert(err < 0); + + if (ERRNO_IS_NEG_NOT_SUPPORTED(err)) + return false; + if (ERRNO_IS_NEG_PRIVILEGE(err)) + return false; + + return !IN_SET(err, -EOVERFLOW, -EINVAL); +} + int name_to_handle_at_loop( int fd, const char *path, @@ -160,19 +178,6 @@ static bool filename_possibly_with_slash_suffix(const char *s) { return filename_is_valid(copied); } -static bool is_name_to_handle_at_fatal_error(int err) { - /* name_to_handle_at() can return "acceptable" errors that are due to the context. For - * example the kernel does not support name_to_handle_at() at all (ENOSYS), or the syscall - * was blocked (EACCES/EPERM; maybe through seccomp, because we are running inside of a - * container), or the mount point is not triggered yet (EOVERFLOW, think nfs4), or some - * general name_to_handle_at() flakiness (EINVAL). However other errors are not supposed to - * happen and therefore are considered fatal ones. */ - - assert(err < 0); - - return !IN_SET(err, -EOPNOTSUPP, -ENOSYS, -EACCES, -EPERM, -EOVERFLOW, -EINVAL); -} - int fd_is_mount_point(int fd, const char *filename, int flags) { _cleanup_free_ struct file_handle *h = NULL, *h_parent = NULL; int mount_id = -1, mount_id_parent = -1; diff --git a/src/basic/mountpoint-util.h b/src/basic/mountpoint-util.h index 90a1343e0c2..26afbb653de 100644 --- a/src/basic/mountpoint-util.h +++ b/src/basic/mountpoint-util.h @@ -36,6 +36,8 @@ #define TMPFS_LIMITS_ROOTFS TMPFS_LIMITS_VAR #define TMPFS_LIMITS_VOLATILE_STATE TMPFS_LIMITS_VAR +bool is_name_to_handle_at_fatal_error(int err); + int name_to_handle_at_loop(int fd, const char *path, struct file_handle **ret_handle, int *ret_mnt_id, int flags); int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret); -- 2.47.3