diff mbox

[Resend,1/2] ceph: introudce a variable to avoid calling refcount_read() twice

Message ID 20180712084508.24131-1-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu July 12, 2018, 8:45 a.m. UTC
Calling refcount_read() twice may return different value each time,
so introduce a variable to avoid it.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
Sorry, I just wrote wrong email address in previous sending, so resend it.
If you have received previous email please ignore it, thanks.

 fs/ceph/mds_client.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Yan, Zheng July 13, 2018, 1:05 p.m. UTC | #1
On Thu, Jul 12, 2018 at 4:47 PM Chengguang Xu <cgxu519@gmx.com> wrote:
>
> Calling refcount_read() twice may return different value each time,
> so introduce a variable to avoid it.
>
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> ---
> Sorry, I just wrote wrong email address in previous sending, so resend it.
> If you have received previous email please ignore it, thanks.
>
>  fs/ceph/mds_client.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index df0a3bb0f6a5..2a8d4cc69eb6 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s)
>
>  static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
>  {
> +
> +
>         if (refcount_inc_not_zero(&s->s_ref)) {

"unsigned int refcnt = refcount_read(&s->s_ref);" should be here


> -               dout("mdsc get_session %p %d -> %d\n", s,
> -                    refcount_read(&s->s_ref)-1, refcount_read(&s->s_ref));
> +               dout("mdsc get_session %p %d -> %d\n", s, refcnt - 1, refcnt);


>                 return s;
>         } else {
>                 dout("mdsc get_session %p 0 -- FAIL\n", s);
> @@ -411,8 +412,9 @@ static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
>
>  void ceph_put_mds_session(struct ceph_mds_session *s)
>  {
> -       dout("mdsc put_session %p %d -> %d\n", s,
> -            refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1);
> +       unsigned int refcnt = refcount_read(&s->s_ref);
> +
> +       dout("mdsc put_session %p %d -> %d\n", s, refcnt, refcnt - 1);
>         if (refcount_dec_and_test(&s->s_ref)) {
>                 if (s->s_auth.authorizer)
>                         ceph_auth_destroy_authorizer(s->s_auth.authorizer);
> --
> 2.17.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chengguang Xu July 13, 2018, 1:27 p.m. UTC | #2
On 2018/7/13 at 下午9:05, Yan, Zheng wrote:

> On Thu, Jul 12, 2018 at 4:47 PM Chengguang Xu <cgxu519@gmx.com> wrote:
> >
> > Calling refcount_read() twice may return different value each time,
> > so introduce a variable to avoid it.
> >
> > Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> > ---
> > Sorry, I just wrote wrong email address in previous sending, so resend it.
> > If you have received previous email please ignore it, thanks.
> >
> >  fs/ceph/mds_client.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> > index df0a3bb0f6a5..2a8d4cc69eb6 100644
> > --- a/fs/ceph/mds_client.c
> > +++ b/fs/ceph/mds_client.c
> > @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s)
> >
> >  static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
> >  {
> > +
> > +
> >         if (refcount_inc_not_zero(&s->s_ref)) {
> 
> "unsigned int refcnt = refcount_read(&s->s_ref);" should be here

Yeah, indeed. Should I send revised patch?

Thanks,
Chengguang
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yan, Zheng July 16, 2018, 12:28 a.m. UTC | #3
On Fri, Jul 13, 2018 at 9:27 PM Chengguang Xu <cgxu519@gmx.com> wrote:
>
>
> On 2018/7/13 at 下午9:05, Yan, Zheng wrote:
>
> > On Thu, Jul 12, 2018 at 4:47 PM Chengguang Xu <cgxu519@gmx.com> wrote:
> > >
> > > Calling refcount_read() twice may return different value each time,
> > > so introduce a variable to avoid it.
> > >
> > > Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> > > ---
> > > Sorry, I just wrote wrong email address in previous sending, so resend it.
> > > If you have received previous email please ignore it, thanks.
> > >
> > >  fs/ceph/mds_client.c | 10 ++++++----
> > >  1 file changed, 6 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> > > index df0a3bb0f6a5..2a8d4cc69eb6 100644
> > > --- a/fs/ceph/mds_client.c
> > > +++ b/fs/ceph/mds_client.c
> > > @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s)
> > >
> > >  static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
> > >  {
> > > +
> > > +
> > >         if (refcount_inc_not_zero(&s->s_ref)) {
> >
> > "unsigned int refcnt = refcount_read(&s->s_ref);" should be here
>
> Yeah, indeed. Should I send revised patch?
>
I fixed it locally

> Thanks,
> Chengguang
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chengguang Xu July 16, 2018, 1:28 a.m. UTC | #4
On 07/16/2018 08:28 AM, Yan, Zheng wrote:
> On Fri, Jul 13, 2018 at 9:27 PM Chengguang Xu <cgxu519@gmx.com> wrote:
>>
>> On 2018/7/13 at 下午9:05, Yan, Zheng wrote:
>>
>>> On Thu, Jul 12, 2018 at 4:47 PM Chengguang Xu <cgxu519@gmx.com> wrote:
>>>> Calling refcount_read() twice may return different value each time,
>>>> so introduce a variable to avoid it.
>>>>
>>>> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
>>>> ---
>>>> Sorry, I just wrote wrong email address in previous sending, so resend it.
>>>> If you have received previous email please ignore it, thanks.
>>>>
>>>>   fs/ceph/mds_client.c | 10 ++++++----
>>>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
>>>> index df0a3bb0f6a5..2a8d4cc69eb6 100644
>>>> --- a/fs/ceph/mds_client.c
>>>> +++ b/fs/ceph/mds_client.c
>>>> @@ -399,9 +399,10 @@ const char *ceph_session_state_name(int s)
>>>>
>>>>   static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
>>>>   {
>>>> +
>>>> +
>>>>          if (refcount_inc_not_zero(&s->s_ref)) {
>>> "unsigned int refcnt = refcount_read(&s->s_ref);" should be here
>> Yeah, indeed. Should I send revised patch?
>>
> I fixed it locally

Thank you for doing that!

Chengguang

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index df0a3bb0f6a5..2a8d4cc69eb6 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -399,9 +399,10 @@  const char *ceph_session_state_name(int s)
 
 static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
 {
+	unsigned int refcnt = refcount_read(&s->s_ref);
+
 	if (refcount_inc_not_zero(&s->s_ref)) {
-		dout("mdsc get_session %p %d -> %d\n", s,
-		     refcount_read(&s->s_ref)-1, refcount_read(&s->s_ref));
+		dout("mdsc get_session %p %d -> %d\n", s, refcnt - 1, refcnt);
 		return s;
 	} else {
 		dout("mdsc get_session %p 0 -- FAIL\n", s);
@@ -411,8 +412,9 @@  static struct ceph_mds_session *get_session(struct ceph_mds_session *s)
 
 void ceph_put_mds_session(struct ceph_mds_session *s)
 {
-	dout("mdsc put_session %p %d -> %d\n", s,
-	     refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1);
+	unsigned int refcnt = refcount_read(&s->s_ref);
+
+	dout("mdsc put_session %p %d -> %d\n", s, refcnt, refcnt - 1);
 	if (refcount_dec_and_test(&s->s_ref)) {
 		if (s->s_auth.authorizer)
 			ceph_auth_destroy_authorizer(s->s_auth.authorizer);