All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: "Yan, Zheng" <zyan@redhat.com>,
	ceph-devel@vger.kernel.org, idryomov@gmail.com
Subject: Re: [PATCH 3/5] ceph: optimize flock encoding during reconnect
Date: Tue, 12 Sep 2017 09:03:24 -0400	[thread overview]
Message-ID: <1505221404.28831.2.camel@redhat.com> (raw)
In-Reply-To: <20170912025351.42147-4-zyan@redhat.com>

On Tue, 2017-09-12 at 10:53 +0800, Yan, Zheng wrote:
> don't malloc if there is no flock
> 
> Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
> ---
>  fs/ceph/locks.c      | 17 ++++++++++-------
>  fs/ceph/mds_client.c | 34 ++++++++++++++++++++--------------
>  2 files changed, 30 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
> index 33e091e6e8d3..4addd18ac6f9 100644
> --- a/fs/ceph/locks.c
> +++ b/fs/ceph/locks.c
> @@ -430,19 +430,22 @@ int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
>  	if (err)
>  		goto out_fail;
>  
> -	err = ceph_pagelist_append(pagelist, flocks,
> -				   num_fcntl_locks * sizeof(*flocks));
> -	if (err)
> -		goto out_fail;
> +	if (num_fcntl_locks > 0) {
> +		err = ceph_pagelist_append(pagelist, flocks,
> +					   num_fcntl_locks * sizeof(*flocks));
> +		if (err)
> +			goto out_fail;
> +	}

Maybe it would be cleaner to just have ceph_pagelist_append immediately
return 0 when len == 0? Looks like it's basically a no-op otherwise.
>  
>  	nlocks = cpu_to_le32(num_flock_locks);
>  	err = ceph_pagelist_append(pagelist, &nlocks, sizeof(nlocks));
>  	if (err)
>  		goto out_fail;
>  
> -	err = ceph_pagelist_append(pagelist,
> -				   &flocks[num_fcntl_locks],
> -				   num_flock_locks * sizeof(*flocks));
> +	if (num_flock_locks > 0) {
> +		err = ceph_pagelist_append(pagelist, &flocks[num_fcntl_locks],
> +					   num_flock_locks * sizeof(*flocks));
> +	}
>  out_fail:
>  	return err;
>  }
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index 6146af4ed03c..817ea438aa19 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -2895,26 +2895,32 @@ static int encode_caps_cb(struct inode *inode, struct ceph_cap *cap,
>  
>  	if (recon_state->msg_version >= 2) {
>  		int num_fcntl_locks, num_flock_locks;
> -		struct ceph_filelock *flocks;
> +		struct ceph_filelock *flocks = NULL;
>  		size_t struct_len, total_len = 0;
>  		u8 struct_v = 0;
>  
>  encode_again:
>  		ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks);
> -		flocks = kmalloc((num_fcntl_locks+num_flock_locks) *
> -				 sizeof(struct ceph_filelock), GFP_NOFS);
> -		if (!flocks) {
> -			err = -ENOMEM;
> -			goto out_free;
> -		}
> -		err = ceph_encode_locks_to_buffer(inode, flocks,
> -						  num_fcntl_locks,
> -						  num_flock_locks);
> -		if (err) {
> +		if (num_fcntl_locks + num_flock_locks > 0) {
> +			flocks = kmalloc((num_fcntl_locks + num_flock_locks) *
> +					 sizeof(struct ceph_filelock), GFP_NOFS);
> +			if (!flocks) {
> +				err = -ENOMEM;
> +				goto out_free;
> +			}
> +			err = ceph_encode_locks_to_buffer(inode, flocks,
> +							  num_fcntl_locks,
> +							  num_flock_locks);
> +			if (err) {
> +				kfree(flocks);
> +				flocks = NULL;
> +				if (err == -ENOSPC)
> +					goto encode_again;
> +				goto out_free;
> +			}
> +		} else {
>  			kfree(flocks);
> -			if (err == -ENOSPC)
> -				goto encode_again;
> -			goto out_free;
> +			flocks = NULL;
>  		}
>  
>  		if (recon_state->msg_version >= 3) {

Looks fine other than the nit above:

Reviewed-by: Jeff Layton <jlayton@redhat.com>

  reply	other threads:[~2017-09-12 13:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-12  2:53 [PATCH 0/5] ceph: file lock related fixes Yan, Zheng
2017-09-12  2:53 ` [PATCH 1/5] ceph: keep auth cap when inode has flocks or posix locks Yan, Zheng
2017-09-12 10:56   ` Jeff Layton
2017-09-12 12:57     ` Yan, Zheng
2017-09-12 13:21   ` Jeff Layton
2017-09-12 13:36     ` Yan, Zheng
2017-09-18 15:06       ` Jeff Layton
2017-09-12  2:53 ` [PATCH 2/5] ceph: make lock_to_ceph_filelock() 'static' Yan, Zheng
2017-09-12 12:48   ` Jeff Layton
2017-09-12  2:53 ` [PATCH 3/5] ceph: optimize flock encoding during reconnect Yan, Zheng
2017-09-12 13:03   ` Jeff Layton [this message]
2017-09-12  2:53 ` [PATCH 4/5] ceph: handle 'session get evicted while there are file locks' Yan, Zheng
2017-09-12 13:13   ` Jeff Layton
2017-09-12  2:53 ` [PATCH 5/5] ceph: avoid null pointer derefernece in case of utsname() return NULL Yan, Zheng
2017-09-12 13:15   ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505221404.28831.2.camel@redhat.com \
    --to=jlayton@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=zyan@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.