diff mbox

[3/5] 9p: Simplify the xattr handlers

Message ID 1441367842-25079-4-git-send-email-agruenba@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andreas Grünbacher Sept. 4, 2015, 11:57 a.m. UTC
The generic_{get,set,remove}xattr inode operations use the xattr name prefix to
decide which of the defined xattr handlers to call, then call the appropriate
handler's get or set operation.  The name suffix is passed to the get or set
operations, the prefix is still "there" in the name before the suffix though.
There is no need to recompose the name in a temporary buffer.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/9p/xattr_security.c | 34 ++++------------------------------
 fs/9p/xattr_trusted.c  | 34 ++++------------------------------
 fs/9p/xattr_user.c     | 34 ++++------------------------------
 3 files changed, 12 insertions(+), 90 deletions(-)

Comments

Christoph Hellwig Sept. 16, 2015, 2:14 p.m. UTC | #1
> +	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;

Please add something like an xattr_full_name() helper to xattr.h that
does this in one place and with proper documentation.

Otherwise looks fine.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Aneesh Kumar K.V Sept. 21, 2015, 7:30 a.m. UTC | #2
Andreas Gruenbacher <andreas.gruenbacher@gmail.com> writes:

> The generic_{get,set,remove}xattr inode operations use the xattr name prefix to
> decide which of the defined xattr handlers to call, then call the appropriate
> handler's get or set operation.  The name suffix is passed to the get or set
> operations, the prefix is still "there" in the name before the suffix though.
> There is no need to recompose the name in a temporary buffer.
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
>  fs/9p/xattr_security.c | 34 ++++------------------------------
>  fs/9p/xattr_trusted.c  | 34 ++++------------------------------
>  fs/9p/xattr_user.c     | 34 ++++------------------------------
>  3 files changed, 12 insertions(+), 90 deletions(-)
>
> diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c
> index cb247a1..2c9b394 100644
> --- a/fs/9p/xattr_security.c
> +++ b/fs/9p/xattr_security.c
> @@ -22,10 +22,7 @@
>  static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
>  			void *buffer, size_t size, int type)
>  {
> -	int retval;
> -	char *full_name;
> -	size_t name_len;
> -	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
> +	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
>  
>  	if (name == NULL)
>  		return -EINVAL;
> @@ -33,26 +30,13 @@ static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
>  	if (strcmp(name, "") == 0)
>  		return -EINVAL;
>  
> -	name_len = strlen(name);
> -	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
> -	if (!full_name)
> -		return -ENOMEM;
> -	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
> -	memcpy(full_name+prefix_len, name, name_len);
> -	full_name[prefix_len + name_len] = '\0';
> -
> -	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
> -	kfree(full_name);
> -	return retval;
> +	return v9fs_xattr_get(dentry, full_name, buffer, size);
>  }
>  

I look strange, to expect that name argument passed to ->get() will have
the full name details. In any case this need more documentation and a
helper as Christoph suggested

-aneesh



--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c
index cb247a1..2c9b394 100644
--- a/fs/9p/xattr_security.c
+++ b/fs/9p/xattr_security.c
@@ -22,10 +22,7 @@ 
 static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@  static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@  static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_security_handler = {
diff --git a/fs/9p/xattr_trusted.c b/fs/9p/xattr_trusted.c
index e30d33b..ee470b6 100644
--- a/fs/9p/xattr_trusted.c
+++ b/fs/9p/xattr_trusted.c
@@ -22,10 +22,7 @@ 
 static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@  static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@  static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_trusted_handler = {
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c
index d0b701b..4432604 100644
--- a/fs/9p/xattr_user.c
+++ b/fs/9p/xattr_user.c
@@ -22,10 +22,7 @@ 
 static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@  static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@  static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_user_handler = {