Re: [PATCH] vfs: Deduplicate code shared by xattr system calls operating on paths

2014-10-12 Thread Christoph Hellwig
On Sun, Oct 12, 2014 at 11:59:58AM -0500, Eric Biggers wrote:
> 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.

Looks good,

Reviewed-by: Christoph Hellwig 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-10-12 Thread Eric Biggers
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: Eric Biggers 
---
 fs/xattr.c | 116 +
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index c69e6d4..64e83ef 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -364,13 +364,12 @@ out:
return error;
 }
 
-SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
-   const char __user *, name, const void __user *, value,
-   size_t, size, int, flags)
+static int path_setxattr(const char __user *pathname,
+const char __user *name, const void __user *value,
+size_t size, int flags, unsigned int lookup_flags)
 {
struct path path;
int error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -388,28 +387,18 @@ retry:
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,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
 {
-   struct path path;
-   int error;
-   unsigned int lookup_flags = 0;
-retry:
-   error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
-   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();
-   if (retry_estale(error, lookup_flags)) {
-   lookup_flags |= LOOKUP_REVAL;
-   goto retry;
-   }
-   return error;
+   return path_setxattr(pathname, name, value, size, flags, 0);
 }
 
 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void 
__user *value,
return error;
 }
 
-SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
-   const char __user *, name, void __user *, value, size_t, size)
+static ssize_t path_getxattr(const char __user *pathname,
+const char __user *name, void __user *value,
+size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -500,23 +489,16 @@ retry:
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,
const char __user *, name, void __user *, value, size_t, size)
 {
-   struct path path;
-   ssize_t error;
-   unsigned int lookup_flags = 0;
-retry:
-   error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
-   if (error)
-   return error;
-   error = getxattr(path.dentry, name, value, size);
-   path_put();
-   if (retry_estale(error, lookup_flags)) {
-   lookup_flags |= LOOKUP_REVAL;
-   goto retry;
-   }
-   return error;
+   return path_getxattr(pathname, name, value, size, 0);
 }
 
 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t 
size)
return error;
 }
 
-SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
-   size_t, size)
+static ssize_t path_listxattr(const char __user *pathname, char __user *list,
+ size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -590,23 +571,16 @@ retry:
return error;
 }
 
+SYSCALL_DEFINE3(listxattr, const char 

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

2014-10-12 Thread Eric Biggers
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: Eric Biggers ebigge...@gmail.com
---
 fs/xattr.c | 116 +
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index c69e6d4..64e83ef 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -364,13 +364,12 @@ out:
return error;
 }
 
-SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
-   const char __user *, name, const void __user *, value,
-   size_t, size, int, flags)
+static int path_setxattr(const char __user *pathname,
+const char __user *name, const void __user *value,
+size_t size, int flags, unsigned int lookup_flags)
 {
struct path path;
int error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -388,28 +387,18 @@ retry:
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,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
 {
-   struct path path;
-   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;
+   return path_setxattr(pathname, name, value, size, flags, 0);
 }
 
 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void 
__user *value,
return error;
 }
 
-SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
-   const char __user *, name, void __user *, value, size_t, size)
+static ssize_t path_getxattr(const char __user *pathname,
+const char __user *name, void __user *value,
+size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -500,23 +489,16 @@ retry:
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,
const char __user *, name, void __user *, value, size_t, size)
 {
-   struct path path;
-   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;
+   return path_getxattr(pathname, name, value, size, 0);
 }
 
 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t 
size)
return error;
 }
 
-SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
-   size_t, size)
+static ssize_t path_listxattr(const char __user *pathname, char __user *list,
+ size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -590,23 +571,16 @@ retry:
return 

Re: [PATCH] vfs: Deduplicate code shared by xattr system calls operating on paths

2014-10-12 Thread Christoph Hellwig
On Sun, Oct 12, 2014 at 11:59:58AM -0500, Eric Biggers wrote:
 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.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] vfs: Deduplicate code shared by xattr system calls operating on paths

2014-03-20 Thread Christoph Hellwig
Looks good,

Reviewed-by: Christoph Hellwig 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] vfs: Deduplicate code shared by xattr system calls operating on paths

2014-03-20 Thread Christoph Hellwig
Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-03-19 Thread Eric Biggers
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.

Signed-off-by: Eric Biggers 
---
 fs/xattr.c | 116 +
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index 3377dff..dcf053e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -364,13 +364,12 @@ out:
return error;
 }
 
-SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
-   const char __user *, name, const void __user *, value,
-   size_t, size, int, flags)
+static int path_setxattr(const char __user *pathname,
+const char __user *name, const void __user *value,
+size_t size, int flags, unsigned int lookup_flags)
 {
struct path path;
int error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -388,28 +387,18 @@ retry:
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,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
 {
-   struct path path;
-   int error;
-   unsigned int lookup_flags = 0;
-retry:
-   error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
-   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();
-   if (retry_estale(error, lookup_flags)) {
-   lookup_flags |= LOOKUP_REVAL;
-   goto retry;
-   }
-   return error;
+   return path_setxattr(pathname, name, value, size, flags, 0);
 }
 
 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void 
__user *value,
return error;
 }
 
-SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
-   const char __user *, name, void __user *, value, size_t, size)
+static ssize_t path_getxattr(const char __user *pathname,
+const char __user *name, void __user *value,
+size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -500,23 +489,16 @@ retry:
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,
const char __user *, name, void __user *, value, size_t, size)
 {
-   struct path path;
-   ssize_t error;
-   unsigned int lookup_flags = 0;
-retry:
-   error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
-   if (error)
-   return error;
-   error = getxattr(path.dentry, name, value, size);
-   path_put();
-   if (retry_estale(error, lookup_flags)) {
-   lookup_flags |= LOOKUP_REVAL;
-   goto retry;
-   }
-   return error;
+   return path_getxattr(pathname, name, value, size, 0);
 }
 
 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t 
size)
return error;
 }
 
-SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
-   size_t, size)
+static ssize_t path_listxattr(const char __user *pathname, char __user *list,
+ size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, );
if (error)
@@ -590,23 +571,16 @@ retry:
return error;
 }
 
+SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
+   size_t, size)
+{

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

2014-03-19 Thread Eric Biggers
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.

Signed-off-by: Eric Biggers ebigge...@gmail.com
---
 fs/xattr.c | 116 +
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/fs/xattr.c b/fs/xattr.c
index 3377dff..dcf053e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -364,13 +364,12 @@ out:
return error;
 }
 
-SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
-   const char __user *, name, const void __user *, value,
-   size_t, size, int, flags)
+static int path_setxattr(const char __user *pathname,
+const char __user *name, const void __user *value,
+size_t size, int flags, unsigned int lookup_flags)
 {
struct path path;
int error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -388,28 +387,18 @@ retry:
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,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
 {
-   struct path path;
-   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;
+   return path_setxattr(pathname, name, value, size, flags, 0);
 }
 
 SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
@@ -481,12 +470,12 @@ getxattr(struct dentry *d, const char __user *name, void 
__user *value,
return error;
 }
 
-SYSCALL_DEFINE4(getxattr, const char __user *, pathname,
-   const char __user *, name, void __user *, value, size_t, size)
+static ssize_t path_getxattr(const char __user *pathname,
+const char __user *name, void __user *value,
+size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -500,23 +489,16 @@ retry:
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,
const char __user *, name, void __user *, value, size_t, size)
 {
-   struct path path;
-   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;
+   return path_getxattr(pathname, name, value, size, 0);
 }
 
 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
@@ -571,12 +553,11 @@ listxattr(struct dentry *d, char __user *list, size_t 
size)
return error;
 }
 
-SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
-   size_t, size)
+static ssize_t path_listxattr(const char __user *pathname, char __user *list,
+ size_t size, unsigned int lookup_flags)
 {
struct path path;
ssize_t error;
-   unsigned int lookup_flags = LOOKUP_FOLLOW;
 retry:
error = user_path_at(AT_FDCWD, pathname, lookup_flags, path);
if (error)
@@ -590,23 +571,16 @@ retry:
return error;
 }
 
+SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char