2006-07-25 04:20:58

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH 002 of 9] knfsd: knfsd: Remove an unused variable from e_show().

On Tuesday July 25, [email protected] wrote:
> On Tue, Jul 25, 2006 at 11:54:32AM +1000, NeilBrown wrote:
> ...
> > diff .prev/fs/nfsd/export.c ./fs/nfsd/export.c
> > --- .prev/fs/nfsd/export.c 2006-07-24 14:33:06.000000000 +1000
> > +++ ./fs/nfsd/export.c 2006-07-24 14:33:26.000000000 +1000
> > @@ -1178,7 +1178,6 @@ static int e_show(struct seq_file *m, vo
> ...
> > if (p == (void *)1) {
>
> I'm not an NFS expert, but the above makes me want to puke. Isn't there a
> cleaner way of doing whatever needs to be done without:
>
> 1) hard-coding a constant
> 2) comparing a variable to an arbitrary pointer
>

Probably. We just need a pointer value that is definitely not a
pointer to a valid cache_head object, and is not NULL.
(void*)1 seems a reasonable choice, but maybe #defineing something
would help.

Patches welcome.

NeilBrown

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2006-07-25 04:25:10

by Greg Banks

[permalink] [raw]
Subject: Re: [PATCH 002 of 9] knfsd: knfsd: Remove an unused variable from e_show().

On Tue, 2006-07-25 at 14:20, Neil Brown wrote:
> On Tuesday July 25, [email protected] wrote:
> > On Tue, Jul 25, 2006 at 11:54:32AM +1000, NeilBrown wrote:
> > ...
> > > diff .prev/fs/nfsd/export.c ./fs/nfsd/export.c
> > > --- .prev/fs/nfsd/export.c 2006-07-24 14:33:06.000000000 +1000
> > > +++ ./fs/nfsd/export.c 2006-07-24 14:33:26.000000000 +1000
> > > @@ -1178,7 +1178,6 @@ static int e_show(struct seq_file *m, vo
> > ...
> > > if (p == (void *)1) {
> >
> > I'm not an NFS expert, but the above makes me want to puke. Isn't there a
> > cleaner way of doing whatever needs to be done without:
> >
> > 1) hard-coding a constant
> > 2) comparing a variable to an arbitrary pointer
> >
>
> Probably. We just need a pointer value that is definitely not a
> pointer to a valid cache_head object, and is not NULL.
> (void*)1 seems a reasonable choice, but maybe #defineing something
> would help.

include/linux/seq_file.h:

#define SEQ_START_TOKEN ((void *)1)

Greg.
--
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2006-07-25 04:32:40

by Greg Banks

[permalink] [raw]
Subject: Re: [PATCH 002 of 9] knfsd: knfsd: Remove an unused variable from e_show().

On Tue, 2006-07-25 at 14:20, Neil Brown wrote:
> On Tuesday July 25, [email protected] wrote:
> > On Tue, Jul 25, 2006 at 11:54:32AM +1000, NeilBrown wrote:
> > ...
>
> Probably. We just need a pointer value that is definitely not a
> pointer to a valid cache_head object, and is not NULL.
> (void*)1 seems a reasonable choice, but maybe #defineing something
> would help.
>
> Patches welcome.

This trivial patch compiles.
--

knfsd: Use SEQ_START_TOKEN instead of hardcoded magic (void*)1.

Signed-off-by: Greg Banks <[email protected]>
---

fs/nfsd/export.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

Index: linux/fs/nfsd/export.c
===================================================================
--- linux.orig/fs/nfsd/export.c 2006-07-25 14:28:03.000000000 +1000
+++ linux/fs/nfsd/export.c 2006-07-25 14:29:14.526574385 +1000
@@ -1086,7 +1086,7 @@ static void *e_start(struct seq_file *m,
exp_readlock();
read_lock(&svc_export_cache.hash_lock);
if (!n--)
- return (void*)1;
+ return SEQ_START_TOKEN;
hash = n >> 32;
export = n & ((1LL<<32) - 1);

@@ -1110,7 +1110,7 @@ static void *e_next(struct seq_file *m,
struct cache_head *ch = p;
int hash = (*pos >> 32);

- if (p == (void*)1)
+ if (p == SEQ_START_TOKEN)
hash = 0;
else if (ch->next == NULL) {
hash++;
@@ -1180,7 +1180,7 @@ static int e_show(struct seq_file *m, vo
struct svc_export *exp = container_of(cp, struct svc_export, h);
svc_client *clp;

- if (p == (void*)1) {
+ if (p == SEQ_START_TOKEN) {
seq_puts(m, "# Version 1.1\n");
seq_puts(m, "# Path Client(Flags) # IPs\n");
return 0;



Greg.
--
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2006-07-25 05:53:20

by Greg Banks

[permalink] [raw]
Subject: Re: [PATCH 002 of 9] knfsd: knfsd: Remove an unused variable from e_show().

On Tue, 2006-07-25 at 14:32, Greg Banks wrote:
> On Tue, 2006-07-25 at 14:20, Neil Brown wrote:
> > On Tuesday July 25, [email protected] wrote:
> > > On Tue, Jul 25, 2006 at 11:54:32AM +1000, NeilBrown wrote:
> > > ...
> >
> > Probably. We just need a pointer value that is definitely not a
> > pointer to a valid cache_head object, and is not NULL.
> > (void*)1 seems a reasonable choice, but maybe #defineing something
> > would help.
> >
> > Patches welcome.
>
> This trivial patch compiles.

But only applies to sles10 <sigh>. Here's the version
which applies to today's GIT.
--

knfsd: Use SEQ_START_TOKEN instead of hardcoded magic (void*)1.

Signed-off-by: Greg Banks <[email protected]>
---

fs/nfsd/export.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

Index: linus-git/fs/nfsd/export.c
===================================================================
--- linus-git.orig/fs/nfsd/export.c 2006-07-25 14:55:28.000000000 +1000
+++ linus-git/fs/nfsd/export.c 2006-07-25 15:40:03.987257265 +1000
@@ -1086,7 +1086,7 @@ static void *e_start(struct seq_file *m,
exp_readlock();
read_lock(&svc_export_cache.hash_lock);
if (!n--)
- return (void *)1;
+ return SEQ_START_TOKEN;
hash = n >> 32;
export = n & ((1LL<<32) - 1);

@@ -1110,7 +1110,7 @@ static void *e_next(struct seq_file *m,
struct cache_head *ch = p;
int hash = (*pos >> 32);

- if (p == (void *)1)
+ if (p == SEQ_START_TOKEN)
hash = 0;
else if (ch->next == NULL) {
hash++;
@@ -1179,7 +1179,7 @@ static int e_show(struct seq_file *m, vo
struct cache_head *cp = p;
struct svc_export *exp = container_of(cp, struct svc_export, h);

- if (p == (void *)1) {
+ if (p == SEQ_START_TOKEN) {
seq_puts(m, "# Version 1.1\n");
seq_puts(m, "# Path Client(Flags) # IPs\n");
return 0;


Greg.
--
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs