diff mbox series

hurd: Avoid file_check_access () RPC for access (F_OK)

Message ID 20240919101439.179663-1-bugaevc@gmail.com
State New
Headers show
Series hurd: Avoid file_check_access () RPC for access (F_OK) | expand

Commit Message

Sergey Bugaev Sept. 19, 2024, 10:14 a.m. UTC
A common use case of access () / faccessat () is checking for file
existence, not any specific access permissions.  In that case, we can
avoid doing the file_check_access () RPC; whether the given path had
been successfully resolved to a file is all we need to know to answer.

This is prompted by GLib switching to use faccessat (F_OK) to implement
g_file_query_exists () for local files.
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4272

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 sysdeps/mach/hurd/faccessat.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Samuel Thibault Sept. 19, 2024, 12:18 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev, le jeu. 19 sept. 2024 13:14:39 +0300, a ecrit:
> A common use case of access () / faccessat () is checking for file
> existence, not any specific access permissions.  In that case, we can
> avoid doing the file_check_access () RPC; whether the given path had
> been successfully resolved to a file is all we need to know to answer.
> 
> This is prompted by GLib switching to use faccessat (F_OK) to implement
> g_file_query_exists () for local files.
> https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4272
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
>  sysdeps/mach/hurd/faccessat.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/sysdeps/mach/hurd/faccessat.c b/sysdeps/mach/hurd/faccessat.c
> index 998e31962..6d3d123ab 100644
> --- a/sysdeps/mach/hurd/faccessat.c
> +++ b/sysdeps/mach/hurd/faccessat.c
> @@ -185,6 +185,15 @@ __faccessat_common (int fd, const char *file, int type, int at_flags,
>  	return errfunc (err);
>      }
>  
> +  /* If all we wanted was to check for a file existing at the path,
> +     then we already got our answer, and we don't need to call
> +     file_check_access ().  */
> +  if (type == F_OK)
> +    {
> +      __mach_port_deallocate (__mach_task_self (), io);
> +      return 0;
> +    }
> +
>    /* Find out what types of access we are allowed to this file.  */
>    err = __file_check_access (io, &allowed);
>    __mach_port_deallocate (__mach_task_self (), io);
> -- 
> 2.46.1
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/faccessat.c b/sysdeps/mach/hurd/faccessat.c
index 998e31962..6d3d123ab 100644
--- a/sysdeps/mach/hurd/faccessat.c
+++ b/sysdeps/mach/hurd/faccessat.c
@@ -185,6 +185,15 @@  __faccessat_common (int fd, const char *file, int type, int at_flags,
 	return errfunc (err);
     }
 
+  /* If all we wanted was to check for a file existing at the path,
+     then we already got our answer, and we don't need to call
+     file_check_access ().  */
+  if (type == F_OK)
+    {
+      __mach_port_deallocate (__mach_task_self (), io);
+      return 0;
+    }
+
   /* Find out what types of access we are allowed to this file.  */
   err = __file_check_access (io, &allowed);
   __mach_port_deallocate (__mach_task_self (), io);