diff mbox

ceph: code cleanup for getting random mds

Message ID 1520739723-59247-1-git-send-email-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu March 11, 2018, 3:42 a.m. UTC
The code to verify having one mds is redundant,
and if there is only one active mds should return
immediately.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/ceph/mdsmap.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Yan, Zheng March 12, 2018, 3:50 a.m. UTC | #1
On Sun, Mar 11, 2018 at 11:42 AM, Chengguang Xu <cgxu519@gmx.com> wrote:
> The code to verify having one mds is redundant,
> and if there is only one active mds should return
> immediately.
>
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> ---
>  fs/ceph/mdsmap.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
> index 44e53ab..1e4f07a 100644
> --- a/fs/ceph/mdsmap.c
> +++ b/fs/ceph/mdsmap.c
> @@ -22,10 +22,6 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
>         int n = 0;
>         int i;
>
> -       /* special case for one mds */
> -       if (1 == m->m_num_mds && m->m_info[0].state > 0)
> -               return 0;
> -
>         /* count */
>         for (i = 0; i < m->m_num_mds; i++)
>                 if (m->m_info[i].state > 0)
> @@ -33,6 +29,9 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
>         if (n == 0)
>                 return -1;
>
> +       if (n == 1)
> +               return i;
> +

This change is wrong. For example:

m_num_mds is 2, m_info[0].state > 0, m_info[1].state < 0. this patch
make the function return 2


>         /* pick */
>         n = prandom_u32() % n;
>         i = 0;
> --
> 1.8.3.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 March 12, 2018, 4:14 a.m. UTC | #2
Hi Yan,

You are right, please just drop this patch.

Thanks,
Chengguang.

> Sent: Monday, March 12, 2018 at 11:50 AM
> From: "Yan, Zheng" <ukernel@gmail.com>
> To: "Chengguang Xu" <cgxu519@gmx.com>
> Cc: "Zheng Yan" <zyan@redhat.com>, "Ilya Dryomov" <idryomov@gmail.com>, ceph-devel <ceph-devel@vger.kernel.org>
> Subject: Re: [PATCH] ceph: code cleanup for getting random mds
>
> On Sun, Mar 11, 2018 at 11:42 AM, Chengguang Xu <cgxu519@gmx.com> wrote:
> > The code to verify having one mds is redundant,
> > and if there is only one active mds should return
> > immediately.
> >
> > Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> > ---
> >  fs/ceph/mdsmap.c | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
> > index 44e53ab..1e4f07a 100644
> > --- a/fs/ceph/mdsmap.c
> > +++ b/fs/ceph/mdsmap.c
> > @@ -22,10 +22,6 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
> >         int n = 0;
> >         int i;
> >
> > -       /* special case for one mds */
> > -       if (1 == m->m_num_mds && m->m_info[0].state > 0)
> > -               return 0;
> > -
> >         /* count */
> >         for (i = 0; i < m->m_num_mds; i++)
> >                 if (m->m_info[i].state > 0)
> > @@ -33,6 +29,9 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
> >         if (n == 0)
> >                 return -1;
> >
> > +       if (n == 1)
> > +               return i;
> > +
> 
> This change is wrong. For example:
> 
> m_num_mds is 2, m_info[0].state > 0, m_info[1].state < 0. this patch
> make the function return 2
> 
> 
> >         /* pick */
> >         n = prandom_u32() % n;
> >         i = 0;
> > --
> > 1.8.3.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
diff mbox

Patch

diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index 44e53ab..1e4f07a 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -22,10 +22,6 @@  int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
 	int n = 0;
 	int i;
 
-	/* special case for one mds */
-	if (1 == m->m_num_mds && m->m_info[0].state > 0)
-		return 0;
-
 	/* count */
 	for (i = 0; i < m->m_num_mds; i++)
 		if (m->m_info[i].state > 0)
@@ -33,6 +29,9 @@  int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
 	if (n == 0)
 		return -1;
 
+	if (n == 1)
+		return i;
+
 	/* pick */
 	n = prandom_u32() % n;
 	i = 0;