ceph: do not print the whole xattr value if it's too long
authorXiubo Li <xiubli@redhat.com>
Tue, 28 Feb 2023 12:40:51 +0000 (20:40 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Sun, 30 Apr 2023 10:37:28 +0000 (12:37 +0200)
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.

At the same time fix the function name issue in the debug logs.

Link: https://tracker.ceph.com/issues/58404
Signed-off-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/xattr.c

index f65b07cc33a2471d196d7c2e5bb650db822299e0..8b6b3075f4d14d74b842ebb9cdcba836d76d92ba 100644 (file)
@@ -535,6 +535,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,
@@ -597,7 +599,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
                xattr->should_free_name = update_xattr;
 
                ci->i_xattrs.count++;
-               dout("__set_xattr count=%d\n", ci->i_xattrs.count);
+               dout("%s count=%d\n", __func__, ci->i_xattrs.count);
        } else {
                kfree(*newxattr);
                *newxattr = NULL;
@@ -625,11 +627,13 @@ static int __set_xattr(struct ceph_inode_info *ci,
        if (new) {
                rb_link_node(&xattr->node, parent, p);
                rb_insert_color(&xattr->node, &ci->i_xattrs.index);
-               dout("__set_xattr_val p=%p\n", p);
+               dout("%s p=%p\n", __func__, 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("%s added %llx.%llx xattr %p %.*s=%.*s%s\n", __func__,
+            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;
 }
@@ -655,13 +659,15 @@ 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 = min(xattr->val_len, MAX_XATTR_VAL_PRINT_LEN);
+
+                       dout("%s %s: found %.*s%s\n", __func__, name, len,
+                            xattr->val, xattr->val_len > len ? "..." : "");
                        return xattr;
                }
        }
 
-       dout("__get_xattr %s: not found\n", name);
+       dout("%s %s: not found\n", __func__, name);
 
        return NULL;
 }