Commit 8cc43116 authored by Eric Biggers's avatar Eric Biggers Committed by Al Viro

vfs: Deduplicate code shared by xattr system calls operating on paths

The following pairs of system calls dealing with extended attributes only
differ in their behavior on whether the symbolic link is followed (when
the named file is a symbolic link):

- setxattr() and lsetxattr()
- getxattr() and lgetxattr()
- listxattr() and llistxattr()
- removexattr() and lremovexattr()

Despite this, the implementations all had duplicated code, so this commit
redirects each of the above pairs of system calls to a corresponding
function to which different lookup flags (LOOKUP_FOLLOW or 0) are passed.

For me this reduced the stripped size of xattr.o from 8824 to 8248 bytes.
Signed-off-by: default avatarEric Biggers <ebiggers3@gmail.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 50b220bb
...@@ -364,13 +364,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, ...@@ -364,13 +364,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
return error; return error;
} }
SYSCALL_DEFINE5(setxattr, const char __user *, pathname, static int path_setxattr(const char __user *pathname,
const char __user *, name, const void __user *, value, const char __user *name, const void __user *value,
size_t, size, int, flags) size_t size, int flags, unsigned int lookup_flags)
{ {
struct path path; struct path path;
int error; int error;
unsigned int lookup_flags = LOOKUP_FOLLOW;
retry: retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error) if (error)
...@@ -388,28 +387,18 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname, ...@@ -388,28 +387,18 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
return error; return error;
} }
SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
{
return path_setxattr(pathname, name, value, size, flags, LOOKUP_FOLLOW);
}
SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname, SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value, const char __user *, name, const void __user *, value,
size_t, size, int, flags) size_t, size, int, flags)
{ {
struct path path; return path_setxattr(pathname, name, value, size, flags, 0);
int error;
unsigned int lookup_flags = 0;
retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error)
return error;
error = mnt_want_write(path.mnt);
if (!error) {
error = setxattr(path.dentry, name, value, size, flags);
mnt_drop_write(path.mnt);
}
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
}
return error;
} }
SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
...@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void __user *value, ...@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
return error; return error;
} }
SYSCALL_DEFINE4(getxattr, const char __user *, pathname, static ssize_t path_getxattr(const char __user *pathname,
const char __user *, name, void __user *, value, size_t, size) const char __user *name, void __user *value,
size_t size, unsigned int lookup_flags)
{ {
struct path path; struct path path;
ssize_t error; ssize_t error;
unsigned int lookup_flags = LOOKUP_FOLLOW;
retry: retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error) if (error)
...@@ -500,23 +489,16 @@ SYSCALL_DEFINE4(getxattr, const char __user *, pathname, ...@@ -500,23 +489,16 @@ SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
return error; return error;
} }
SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
const char __user *, name, void __user *, value, size_t, size)
{
return path_getxattr(pathname, name, value, size, LOOKUP_FOLLOW);
}
SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname, SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
const char __user *, name, void __user *, value, size_t, size) const char __user *, name, void __user *, value, size_t, size)
{ {
struct path path; return path_getxattr(pathname, name, value, size, 0);
ssize_t error;
unsigned int lookup_flags = 0;
retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error)
return error;
error = getxattr(path.dentry, name, value, size);
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
}
return error;
} }
SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
...@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t size) ...@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t size)
return error; return error;
} }
SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list, static ssize_t path_listxattr(const char __user *pathname, char __user *list,
size_t, size) size_t size, unsigned int lookup_flags)
{ {
struct path path; struct path path;
ssize_t error; ssize_t error;
unsigned int lookup_flags = LOOKUP_FOLLOW;
retry: retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error) if (error)
...@@ -590,23 +571,16 @@ SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list, ...@@ -590,23 +571,16 @@ SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
return error; return error;
} }
SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
size_t, size)
{
return path_listxattr(pathname, list, size, LOOKUP_FOLLOW);
}
SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list, SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
size_t, size) size_t, size)
{ {
struct path path; return path_listxattr(pathname, list, size, 0);
ssize_t error;
unsigned int lookup_flags = 0;
retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error)
return error;
error = listxattr(path.dentry, list, size);
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
}
return error;
} }
SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
...@@ -640,12 +614,11 @@ removexattr(struct dentry *d, const char __user *name) ...@@ -640,12 +614,11 @@ removexattr(struct dentry *d, const char __user *name)
return vfs_removexattr(d, kname); return vfs_removexattr(d, kname);
} }
SYSCALL_DEFINE2(removexattr, const char __user *, pathname, static int path_removexattr(const char __user *pathname,
const char __user *, name) const char __user *name, unsigned int lookup_flags)
{ {
struct path path; struct path path;
int error; int error;
unsigned int lookup_flags = LOOKUP_FOLLOW;
retry: retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error) if (error)
...@@ -663,27 +636,16 @@ SYSCALL_DEFINE2(removexattr, const char __user *, pathname, ...@@ -663,27 +636,16 @@ SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
return error; return error;
} }
SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
const char __user *, name)
{
return path_removexattr(pathname, name, LOOKUP_FOLLOW);
}
SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname, SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
const char __user *, name) const char __user *, name)
{ {
struct path path; return path_removexattr(pathname, name, 0);
int error;
unsigned int lookup_flags = 0;
retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
if (error)
return error;
error = mnt_want_write(path.mnt);
if (!error) {
error = removexattr(path.dentry, name);
mnt_drop_write(path.mnt);
}
path_put(&path);
if (retry_estale(error, lookup_flags)) {
lookup_flags |= LOOKUP_REVAL;
goto retry;
}
return error;
} }
SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment