]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: make is_name_to_handle_at_fatal_error() an exported API
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Jun 2024 10:35:29 +0000 (12:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 1 Jul 2024 13:45:15 +0000 (15:45 +0200)
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
src/basic/mountpoint-util.h

index de15ac73ca319e1f716231dc56997880accd9aed..73b582f58f36c4d9837545bcf0a090d185f53460 100644 (file)
  * 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;
index 90a1343e0c24698ce2d127cd29bf93d578447141..26afbb653de7d0426e6d95aaa4d46d3f0bdde5bd 100644 (file)
@@ -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);