ceph: do not print the whole xattr value if it's too long
PATCH v3 1/1 ceph: do not print the whole xattr value if it's too long
From: Xiubo Li <[email protected]>
If the xattr's value size is long enough the kernel will warn and then will fail the xfstests test case.
Just print part of the value string if it's too long.
URL: https://tracker.ceph.com/issues/58404
---
V3:
- s/MAX_XATTR_VAL/MAX_XATTR_VAL_PRINT_LEN/g
- removed the CCing stable mail list
fs/ceph/xattr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
fs/ceph/xattr.c +11 -4
@@ -561,6 +561,8 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,return NULL ; } +#define MAX_XATTR_VAL_PRINT_LEN 256 + static int __set_xattr(struct ceph_inode_info *ci, const char *name, int name_len, const char *val, int val_len,
@@ -654,8 +656,10 @@ static int __set_xattr(struct ceph_inode_info *ci,dout ("__set_xattr_val p=%p\n" , p); } -dout ("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s\n" , -ceph_vinop (&ci->netfs.inode), xattr, name_len, name, val_len, val); +dout ("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s%s\n" , +ceph_vinop (&ci->netfs.inode), xattr, name_len, name, +min (val_len,MAX_XATTR_VAL_PRINT_LEN ), val, + val_len >MAX_XATTR_VAL_PRINT_LEN ?"..." :"" );return 0 ; }
@@ -681,8 +685,11 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,else if (c >0 ) p = &(*p)->rb_right;else { -dout ("__get_xattr %s: found %.*s\n" , name, - xattr->val_len, xattr->val); +int len = xattr->val_len; + +dout ("__get_xattr %s: found %.*s%s\n" , name, +min (len,MAX_XATTR_VAL_PRINT_LEN ), xattr->val, + len >MAX_XATTR_VAL_PRINT_LEN ?"..." :"" );return xattr; } }
Signature · 1 line
2.31.1
Ilya Dryomov
maintainerQuoted 34 lines · On Thu, Mar 2, 2023 at 4:26 AM <[email protected]> wrote:
From: Xiubo Li <[email protected]>
If the xattr's value size is long enough the kernel will warn and then will fail the xfstests test case.
Just print part of the value string if it's too long.
URL: https://tracker.ceph.com/issues/58404
Signed-off-by Xiubo Li <[email protected]>---
V3:
- s/MAX_XATTR_VAL/MAX_XATTR_VAL_PRINT_LEN/g
- removed the CCing stable mail listfs/ceph/xattr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)fs/ceph/xattr.c +2
-0@@ -561,6 +561,8 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,return NULL ; } +#define MAX_XATTR_VAL_PRINT_LEN 256 + static int __set_xattr(struct ceph_inode_info *ci, const char *name, int name_len, const char *val, int val_len,
fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 659
Quoted 6 lines
fs/ceph/xattr.c +1
-2@@ -654,8 +656,10 @@ static int __set_xattr(struct ceph_inode_info *ci,dout ("__set_xattr_val p=%p\n" , p); } -dout ("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s\n" , -ceph_vinop (&ci->netfs.inode), xattr, name_len, name, val_len, val); + dout("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s%s\n",
Hi Xiubo,
The function name is incorrect here and above, it should be __set_xattr.
Quoted 7 lines
fs/ceph/xattr.c +3
-0+ceph_vinop (&ci->netfs.inode), xattr, name_len, name, +min (val_len,MAX_XATTR_VAL_PRINT_LEN ), val, + val_len > MAX_XATTR_VAL_PRINT_LEN ? "..." : "");return 0 ; }
fs/ceph/xattr.c static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci, · line 692
Quoted 10 lines
fs/ceph/xattr.c +5
-2@@ -681,8 +685,11 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,else if (c >0 ) p = &(*p)->rb_right;else { -dout ("__get_xattr %s: found %.*s\n" , name, - xattr->val_len, xattr->val); +int len = xattr->val_len; + +dout ("__get_xattr %s: found %.*s%s\n" , name, +min (len,MAX_XATTR_VAL_PRINT_LEN ), xattr->val, + len >MAX_XATTR_VAL_PRINT_LEN ?"..." :"" );
It looks like len variable is introduced just to save a few characters? If you make it meaningful, dout would actually be more compact:
int len = min(xattr->val_len, MAX_XATTR_VAL_PRINT_LEN);
dout("__get_xattr %s: found %.*s%s\n", name, len,
xattr->val, xattr->val_len > len ? "..." : "");Thanks,
Ilya
Quoted 37 lines · Ilya Dryomov
Quoted 36 lines · On Thu, Mar 2, 2023 at 4:26 AM <[email protected]> wrote:
From: Xiubo Li <[email protected]>
If the xattr's value size is long enough the kernel will warn and then will fail the xfstests test case.
Just print part of the value string if it's too long.
URL: https://tracker.ceph.com/issues/58404
Signed-off-by Xiubo Li <[email protected]>---
V3:
- s/MAX_XATTR_VAL/MAX_XATTR_VAL_PRINT_LEN/g
- removed the CCing stable mail listfs/ceph/xattr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)fs/ceph/xattr.c +2
-0@@ -561,6 +561,8 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,return NULL ; } +#define MAX_XATTR_VAL_PRINT_LEN 256 + static int __set_xattr(struct ceph_inode_info *ci, const char *name, int name_len, const char *val, int val_len,@@ -654,8 +656,10 @@ static int __set_xattr(struct ceph_inode_info *ci,dout ("__set_xattr_val p=%p\n" , p); }
Quoted 6 lines
fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 659
Quoted 3 lines
fs/ceph/xattr.c +1
-2-dout ("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s\n" , -ceph_vinop (&ci->netfs.inode), xattr, name_len, name, val_len, val); + dout("__set_xattr_val added %llx.%llx xattr %p %.*s=%.*s%s\n",Hi Xiubo,
The function name is incorrect here and above, it should be
__set_xattr.
yeah, I noticed it. I will revise it.
Quoted 20 lines
Quoted 7 lines
fs/ceph/xattr.c +3
-0+ceph_vinop (&ci->netfs.inode), xattr, name_len, name, +min (val_len,MAX_XATTR_VAL_PRINT_LEN ), val, + val_len > MAX_XATTR_VAL_PRINT_LEN ? "..." : "");return 0 ; }fs/ceph/xattr.c static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci, · line 692
Quoted 10 lines
fs/ceph/xattr.c +5
-2@@ -681,8 +685,11 @@ static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,else if (c >0 ) p = &(*p)->rb_right;else { -dout ("__get_xattr %s: found %.*s\n" , name, - xattr->val_len, xattr->val); +int len = xattr->val_len; + +dout ("__get_xattr %s: found %.*s%s\n" , name, +min (len,MAX_XATTR_VAL_PRINT_LEN ), xattr->val, + len >MAX_XATTR_VAL_PRINT_LEN ?"..." :"" );It looks like len variable is introduced just to save a few characters? If you make it meaningful, dout would actually be more compact:
Quoted 4 lines
int len = min(xattr->val_len, MAX_XATTR_VAL_PRINT_LEN);
dout("__get_xattr %s: found %.*s%s\n", name, len,
xattr->val, xattr->val_len > len ? "..." : "");Just introduced the len var to make sure each line won't exceed 80 chars.
This also looks good. I can revise it together to fix the function name issue.
Thanks,
- Xiubo
Quoted 4 lines
Thanks,
Ilya
Signature · 6 lines
Best Regards, Xiubo Li (李秀波) Email: [email protected]/[email protected] Slack: @Xiubo Li