linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type'
       [not found] <20200817090048.17991-1-jiyin@redhat.com>
@ 2020-08-17 20:33 ` Eric Sandeen
  2020-08-18  3:25   ` Jianhong Yin
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Sandeen @ 2020-08-17 20:33 UTC (permalink / raw)
  To: Jianhong Yin, linux-xfs; +Cc: Jianhong Yin

On 8/17/20 4:00 AM, Jianhong Yin wrote:
> From: Jianhong Yin <yin-jianhong@163.com>
> 
> for power saving and also as a workaround of below issue:
>> xfs_db -r /dev/vda3 -c "inode 132" -c "type inode" -c "inode"
>> current inode number is 128
> 
> Reported-by: Jianhong Yin <jiyin@redhat.com>
> Suggested-by: Eric Sandeen <esandeen@redhat.com>
> Tested-by: Jianhong Yin <yin-jianhong@163.com>
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---
>  db/type.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/db/type.c b/db/type.c
> index 3cb1e868..679de1b0 100644
> --- a/db/type.c
> +++ b/db/type.c
> @@ -213,6 +213,9 @@ type_f(
>  
>  
>  	} else {
> +		if (cur_typ != NULL && strcmp(cur_typ->name, argv[1]) == 0)
> +			return 0;
> +
>  		tt = findtyp(argv[1]);
>  		if (tt == NULL) {
>  			dbprintf(_("no such type %s\n"), argv[1]);

Thanks for this - I had a patch on my stack to do the same thing,
but did I it this way:

diff --git a/db/type.c b/db/type.c
index 3cb1e868..5433bcfb 100644
--- a/db/type.c
+++ b/db/type.c
@@ -219,6 +219,8 @@ type_f(
 		} else {
 			if (iocur_top->typ == NULL)
 				dbprintf(_("no current object\n"));
+			else if (iocur_top->typ == tt)
+				return 0;
 			else {
 				cur_typ = tt;
 				set_iocur_type(tt);

which I guess I like a little better than using strcmp on the argument...
it compares the type structure directly, rather than comparing the names.

-Eric


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

* Re: [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type'
  2020-08-17 20:33 ` [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type' Eric Sandeen
@ 2020-08-18  3:25   ` Jianhong Yin
  0 siblings, 0 replies; 2+ messages in thread
From: Jianhong Yin @ 2020-08-18  3:25 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs, Jianhong Yin


----- 原始邮件 -----
> 发件人: "Eric Sandeen" <esandeen@redhat.com>
> 收件人: "Jianhong Yin" <jiyin@redhat.com>, linux-xfs@vger.kernel.org
> 抄送: "Jianhong Yin" <yin-jianhong@163.com>
> 发送时间: 星期二, 2020年 8 月 18日 上午 4:33:15
> 主题: Re: [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type'
> 
> On 8/17/20 4:00 AM, Jianhong Yin wrote:
> > From: Jianhong Yin <yin-jianhong@163.com>
> > 
> > for power saving and also as a workaround of below issue:
> >> xfs_db -r /dev/vda3 -c "inode 132" -c "type inode" -c "inode"
> >> current inode number is 128
> > 
> > Reported-by: Jianhong Yin <jiyin@redhat.com>
> > Suggested-by: Eric Sandeen <esandeen@redhat.com>
> > Tested-by: Jianhong Yin <yin-jianhong@163.com>
> > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > ---
> >  db/type.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/db/type.c b/db/type.c
> > index 3cb1e868..679de1b0 100644
> > --- a/db/type.c
> > +++ b/db/type.c
> > @@ -213,6 +213,9 @@ type_f(
> >  
> >  
> >  	} else {
> > +		if (cur_typ != NULL && strcmp(cur_typ->name, argv[1]) == 0)
> > +			return 0;
> > +
> >  		tt = findtyp(argv[1]);
> >  		if (tt == NULL) {
> >  			dbprintf(_("no such type %s\n"), argv[1]);
> 
> Thanks for this - I had a patch on my stack to do the same thing,
> but did I it this way:
> 
> diff --git a/db/type.c b/db/type.c
> index 3cb1e868..5433bcfb 100644
> --- a/db/type.c
> +++ b/db/type.c
> @@ -219,6 +219,8 @@ type_f(
>  		} else {
>  			if (iocur_top->typ == NULL)
>  				dbprintf(_("no current object\n"));
> +			else if (iocur_top->typ == tt)
> +				return 0;
>  			else {
>  				cur_typ = tt;
>  				set_iocur_type(tt);
> 
> which I guess I like a little better than using strcmp on the argument...
> it compares the type structure directly, rather than comparing the names.
Good to know that :)

I just thought that 'tt' is also come from findtyp()->forearch:strcmp(argv,)
 and it could save more cpu instructions if compare before findtyp().

but seems I forgot that findtyp() is always needed if curtyp != requested type

"Premature optimization is the root of all evil" ...

Thanks
Jianhong

> 
> -Eric
> 


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

end of thread, other threads:[~2020-08-18  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200817090048.17991-1-jiyin@redhat.com>
2020-08-17 20:33 ` [PATCH] [xfs_db:type] do nothing if 'current type' == 'the requested type' Eric Sandeen
2020-08-18  3:25   ` Jianhong Yin

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).