linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
@ 2022-05-20 11:54 Luís Henriques
  2022-05-20 14:22 ` Luís Henriques
  2022-05-23  1:47 ` Xiubo Li
  0 siblings, 2 replies; 6+ messages in thread
From: Luís Henriques @ 2022-05-20 11:54 UTC (permalink / raw)
  To: Jeff Layton, Xiubo Li, Ilya Dryomov
  Cc: ceph-devel, linux-kernel, Luís Henriques

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>
---
 fs/ceph/xattr.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index afec84088471..09751a5f028c 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -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);
 
@@ -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);
@@ -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;
@@ -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;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
  2022-05-20 11:54 [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size Luís Henriques
@ 2022-05-20 14:22 ` Luís Henriques
  2022-05-23  1:47 ` Xiubo Li
  1 sibling, 0 replies; 6+ messages in thread
From: Luís Henriques @ 2022-05-20 14:22 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Xiubo Li, Ilya Dryomov, ceph-devel, linux-kernel

Luís Henriques <lhenriques@suse.de> writes:

> 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>
> ---
>  fs/ceph/xattr.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
> index afec84088471..09751a5f028c 100644
> --- a/fs/ceph/xattr.c
> +++ b/fs/ceph/xattr.c
> @@ -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);
>  
> @@ -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);

Oops!  Looks like someone ate a '%' char.  Oh well, I won't bother sending
out a new version for now as this is an RFC and the MDS side is what
really needs fixing.  In fact, the client-side may be something very
different from this RFC.

Cheers,
-- 
Luís

>  
>  	/* do request */
>  	req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
> @@ -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;
> @@ -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;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
  2022-05-20 11:54 [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size Luís Henriques
  2022-05-20 14:22 ` Luís Henriques
@ 2022-05-23  1:47 ` Xiubo Li
  2022-05-23  9:47   ` Luís Henriques
  2022-05-23 10:43   ` Jeff Layton
  1 sibling, 2 replies; 6+ messages in thread
From: Xiubo Li @ 2022-05-23  1:47 UTC (permalink / raw)
  To: Luís Henriques, Jeff Layton, Ilya Dryomov; +Cc: ceph-devel, linux-kernel


On 5/20/22 7:54 PM, Luís Henriques wrote:
> 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>
> ---
>   fs/ceph/xattr.c | 17 +++++++++++++----
>   1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
> index afec84088471..09751a5f028c 100644
> --- a/fs/ceph/xattr.c
> +++ b/fs/ceph/xattr.c
> @@ -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 */

The max size is changeable in MDS side. Possibly we should do something 
as mentioned in your ceph PR [1].

@Jeff, any better idea ?


[1] 
https://github.com/ceph/ceph/pull/46357/commits/741f8ba36f14774834c0d5618519425ccf1ccc85#r878966753

Thanks.

-- Xiubo


> +
>   static int __remove_xattr(struct ceph_inode_info *ci,
>   			  struct ceph_inode_xattr *xattr);
>   
> @@ -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);
> @@ -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;
> @@ -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;
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
  2022-05-23  1:47 ` Xiubo Li
@ 2022-05-23  9:47   ` Luís Henriques
  2022-05-23 10:43   ` Jeff Layton
  1 sibling, 0 replies; 6+ messages in thread
From: Luís Henriques @ 2022-05-23  9:47 UTC (permalink / raw)
  To: Xiubo Li; +Cc: Jeff Layton, Ilya Dryomov, ceph-devel, linux-kernel

Xiubo Li <xiubli@redhat.com> writes:

> On 5/20/22 7:54 PM, Luís Henriques wrote:
>> 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>
>> ---
>>   fs/ceph/xattr.c | 17 +++++++++++++----
>>   1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
>> index afec84088471..09751a5f028c 100644
>> --- a/fs/ceph/xattr.c
>> +++ b/fs/ceph/xattr.c
>> @@ -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 */
>
> The max size is changeable in MDS side. Possibly we should do something as
> mentioned in your ceph PR [1].
>

Right, as I mentioned in that PR, having clients that are aware of that
limit will allow them to behave correctly.  But the MDS still needs to
handle the case where these limits are exceeded (for ex. kernel clients
that don't know about this limit).  So, we still need to do something
similar to what I've proposed in there.

Cheers
-- 
Luís

> @Jeff, any better idea ?
>
>
> [1]
> https://github.com/ceph/ceph/pull/46357/commits/741f8ba36f14774834c0d5618519425ccf1ccc85#r878966753
>
> Thanks.
>
> -- Xiubo
>
>
>> +
>>   static int __remove_xattr(struct ceph_inode_info *ci,
>>   			  struct ceph_inode_xattr *xattr);
>>   @@ -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);
>> @@ -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;
>> @@ -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;
>>
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
  2022-05-23  1:47 ` Xiubo Li
  2022-05-23  9:47   ` Luís Henriques
@ 2022-05-23 10:43   ` Jeff Layton
  2022-05-23 12:11     ` Xiubo Li
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff Layton @ 2022-05-23 10:43 UTC (permalink / raw)
  To: Xiubo Li, Luís Henriques, Ilya Dryomov; +Cc: ceph-devel, linux-kernel

On Mon, 2022-05-23 at 09:47 +0800, Xiubo Li wrote:
> On 5/20/22 7:54 PM, Luís Henriques wrote:
> > 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>
> > ---
> >   fs/ceph/xattr.c | 17 +++++++++++++----
> >   1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
> > index afec84088471..09751a5f028c 100644
> > --- a/fs/ceph/xattr.c
> > +++ b/fs/ceph/xattr.c
> > @@ -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 */
> 
> The max size is changeable in MDS side. Possibly we should do something 
> as mentioned in your ceph PR [1].
> 
> @Jeff, any better idea ?
> 
> 
> [1] 
> https://github.com/ceph/ceph/pull/46357/commits/741f8ba36f14774834c0d5618519425ccf1ccc85#r878966753
> 
> Thanks.
> 
> -- Xiubo
> 
> 

Not really.

The idea in the github comment makes sense. Basically, make it so that
the setting isn't changeable at runtime and then have the client query
for the limit at appropriate times.

You can probably still defeat that by changing it and rebooting the MDS,
but I don't see that you can do much else.

> > +
> >   static int __remove_xattr(struct ceph_inode_info *ci,
> >   			  struct ceph_inode_xattr *xattr);
> >   
> > @@ -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);
> > @@ -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;
> > @@ -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;
> > 
> 

-- 
Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size
  2022-05-23 10:43   ` Jeff Layton
@ 2022-05-23 12:11     ` Xiubo Li
  0 siblings, 0 replies; 6+ messages in thread
From: Xiubo Li @ 2022-05-23 12:11 UTC (permalink / raw)
  To: Jeff Layton, Luís Henriques, Ilya Dryomov; +Cc: ceph-devel, linux-kernel


On 5/23/22 6:43 PM, Jeff Layton wrote:
> On Mon, 2022-05-23 at 09:47 +0800, Xiubo Li wrote:
>> On 5/20/22 7:54 PM, Luís Henriques wrote:
>>> 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>
>>> ---
>>>    fs/ceph/xattr.c | 17 +++++++++++++----
>>>    1 file changed, 13 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
>>> index afec84088471..09751a5f028c 100644
>>> --- a/fs/ceph/xattr.c
>>> +++ b/fs/ceph/xattr.c
>>> @@ -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 */
>> The max size is changeable in MDS side. Possibly we should do something
>> as mentioned in your ceph PR [1].
>>
>> @Jeff, any better idea ?
>>
>>
>> [1]
>> https://github.com/ceph/ceph/pull/46357/commits/741f8ba36f14774834c0d5618519425ccf1ccc85#r878966753
>>
>> Thanks.
>>
>> -- Xiubo
>>
>>
> Not really.
>
> The idea in the github comment makes sense. Basically, make it so that
> the setting isn't changeable at runtime and then have the client query
> for the limit at appropriate times.
>
> You can probably still defeat that by changing it and rebooting the MDS,
> but I don't see that you can do much else.

Yeah, sounds good.


>
>>> +
>>>    static int __remove_xattr(struct ceph_inode_info *ci,
>>>    			  struct ceph_inode_xattr *xattr);
>>>    
>>> @@ -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);
>>> @@ -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;
>>> @@ -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;
>>>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-23 12:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 11:54 [RFC PATCH] ceph: try to prevent exceeding the MDS maximum xattr size Luís Henriques
2022-05-20 14:22 ` Luís Henriques
2022-05-23  1:47 ` Xiubo Li
2022-05-23  9:47   ` Luís Henriques
2022-05-23 10:43   ` Jeff Layton
2022-05-23 12:11     ` Xiubo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).