Skip to content

Commit

Permalink
ceph: try to prevent exceeding the MDS maximum xattr size
Browse files Browse the repository at this point in the history
The MDS tries to enforce a limit on the total key/values in extended
attributes.  However, this limit is enforced only if doing a synchronous
operation (MDS_OP_SETXATTR) -- if we're buffering the xattrs, the MDS
doesn't have a chance to enforce these limits.

This patch forces the usage of the synchronous operation if xattrs size hits
the maximum size that is set on the MDS by default (64k).

While there, fix a dout() that would trigger a printk warning:

[   98.718078] ------------[ cut here ]------------
[   98.719012] precision 65536 too large
[   98.719039] WARNING: CPU: 1 PID: 3755 at lib/vsprintf.c:2703 vsnprintf+0x5e3/0x600
...

URL: https://tracker.ceph.com/issues/55725
Signed-off-by: Luís Henriques <lhenriques@suse.de>
  • Loading branch information
luis-henrix authored and intel-lab-lkp committed May 20, 2022
1 parent 642d51f commit 3c9e88c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions fs/ceph/xattr.c
Expand Up @@ -15,6 +15,12 @@
#define XATTR_CEPH_PREFIX "ceph."
#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)

/*
* Maximum size of xattrs the MDS can handle per inode by default. This
* includes the attribute name and 4+4 bytes for the key/value sizes.
*/
#define MDS_MAX_XATTR_PAIRS_SIZE (1<<16) /* 64K */

static int __remove_xattr(struct ceph_inode_info *ci,
struct ceph_inode_xattr *xattr);

Expand Down Expand Up @@ -1078,7 +1084,7 @@ static int ceph_sync_setxattr(struct inode *inode, const char *name,
flags |= CEPH_XATTR_REMOVE;
}

dout("setxattr value=%.*s\n", (int)size, value);
dout("setxattr value size: ld\n", size);

/* do request */
req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
Expand Down Expand Up @@ -1176,8 +1182,13 @@ int __ceph_setxattr(struct inode *inode, const char *name,
spin_lock(&ci->i_ceph_lock);
retry:
issued = __ceph_caps_issued(ci, NULL);
if (ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL))
required_blob_size = __get_required_blob_size(ci, name_len, val_len);
if ((ci->i_xattrs.version == 0) || !(issued & CEPH_CAP_XATTR_EXCL) ||
(required_blob_size >= MDS_MAX_XATTR_PAIRS_SIZE)) {
dout("%s do sync setxattr: version: %llu blob size: %d\n",
__func__, ci->i_xattrs.version, required_blob_size);
goto do_sync;
}

if (!lock_snap_rwsem && !ci->i_head_snapc) {
lock_snap_rwsem = true;
Expand All @@ -1193,8 +1204,6 @@ int __ceph_setxattr(struct inode *inode, const char *name,
ceph_cap_string(issued));
__build_xattrs(inode);

required_blob_size = __get_required_blob_size(ci, name_len, val_len);

if (!ci->i_xattrs.prealloc_blob ||
required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
struct ceph_buffer *blob;
Expand Down

0 comments on commit 3c9e88c

Please sign in to comment.