git: d64356323c10 - releng/14.0 - linux(4): Merge getxattr for future error recode

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Tue, 12 Sep 2023 16:44:09 UTC
The branch releng/14.0 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=d64356323c1058909df7efe772f7ab0843a30f55

commit d64356323c1058909df7efe772f7ab0843a30f55
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-09-01 08:09:49 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-09-12 16:42:13 +0000

    linux(4): Merge getxattr for future error recode
    
    Approved by:            re (gjb)
    Tested by:              zirias
    MFC after:              1 week
    
    (cherry picked from commit 6b46ec66129d9490c91876f72d98e514121996a6)
    (cherry picked from commit 803280ea07e9c07007e0acd3864a18d40b86de2a)
---
 sys/compat/linux/linux_xattr.c | 62 ++++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 17 deletions(-)

diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c
index b54a0d2f89ad..901123684154 100644
--- a/sys/compat/linux/linux_xattr.c
+++ b/sys/compat/linux/linux_xattr.c
@@ -68,6 +68,15 @@ struct setxattr_args {
 	int		follow;
 };
 
+struct getxattr_args {
+	int		fd;
+	const char	*path;
+	const char	*name;
+	void 		*value;
+	l_size_t	size;
+	int		follow;
+};
+
 static char *extattr_namespace_names[] = EXTATTR_NAMESPACE_NAMES;
 
 
@@ -262,47 +271,66 @@ linux_fremovexattr(struct thread *td, struct linux_fremovexattr_args *args)
 }
 
 static int
-linux_path_getxattr(struct thread *td, const char *upath, const char *uname,
-    void *value, l_size_t size, int follow)
+getxattr(struct thread *td, struct getxattr_args *args)
 {
 	char attrname[LINUX_XATTR_NAME_MAX + 1];
 	int attrnamespace, error;
 
-	error = xatrr_to_extattr(uname, &attrnamespace, attrname);
+	error = xatrr_to_extattr(args->name, &attrnamespace, attrname);
 	if (error != 0)
 		return (error);
-
-	return (kern_extattr_get_path(td, upath, attrnamespace,
-	    attrname, value, size, follow, UIO_USERSPACE));
+	if (args->path != NULL)
+		error = kern_extattr_get_path(td, args->path, attrnamespace,
+		    attrname, args->value, args->size, args->follow, UIO_USERSPACE);
+	else
+		error = kern_extattr_get_fd(td, args->fd, attrnamespace,
+		    attrname, args->value, args->size);
+	return (error);
 }
 
 int
 linux_getxattr(struct thread *td, struct linux_getxattr_args *args)
 {
+	struct getxattr_args eargs = {
+		.fd = -1,
+		.path = args->path,
+		.name = args->name,
+		.value = args->value,
+		.size = args->size,
+		.follow = FOLLOW,
+	};
 
-	return (linux_path_getxattr(td, args->path, args->name,
-	    args->value, args->size, FOLLOW));
+	return (getxattr(td, &eargs));
 }
 
 int
 linux_lgetxattr(struct thread *td, struct linux_lgetxattr_args *args)
 {
+	struct getxattr_args eargs = {
+		.fd = -1,
+		.path = args->path,
+		.name = args->name,
+		.value = args->value,
+		.size = args->size,
+		.follow = NOFOLLOW,
+	};
 
-	return (linux_path_getxattr(td, args->path, args->name,
-	    args->value, args->size, NOFOLLOW));
+	return (getxattr(td, &eargs));
 }
 
 int
 linux_fgetxattr(struct thread *td, struct linux_fgetxattr_args *args)
 {
-	char attrname[LINUX_XATTR_NAME_MAX + 1];
-	int attrnamespace, error;
+	struct getxattr_args eargs = {
+		.fd = args->fd,
+		.path = NULL,
+		.name = args->name,
+		.value = args->value,
+		.size = args->size,
+		.follow = 0,
+	};
 
-	error = xatrr_to_extattr(args->name, &attrnamespace, attrname);
-	if (error != 0)
-		return (error);
-	return (kern_extattr_get_fd(td, args->fd, attrnamespace,
-	    attrname, args->value, args->size));
+	return (getxattr(td, &eargs));
 }
 
 static int