David,
Please pull from:
master.kernel.org:/home/acme/BK/net-2.5
Changesets for the other cases and to remove the use of temporary
sprintf stack buffers as well will be sent in the next days.
It is extremely fortunate that all this discussion about seq_file
proper usage has happened at the start of a long series of changesets that will
be sent as required to convert all the tree to seq_file :-)
- Arnaldo
You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.
===================================================================
[email protected], 2002-10-17 02:16:44-03:00, [email protected]
o ipv4: remove the hack, using seq->private to hold state
ip_proc.c | 102 ++++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 64 insertions(+), 38 deletions(-)
diff -Nru a/net/ipv4/ip_proc.c b/net/ipv4/ip_proc.c
--- a/net/ipv4/ip_proc.c Thu Oct 17 02:19:17 2002
+++ b/net/ipv4/ip_proc.c Thu Oct 17 02:19:17 2002
@@ -68,44 +68,42 @@
#endif /* CONFIG_AX25 */
struct arp_iter_state {
- loff_t is_pneigh: 1,
- bucket: 6,
- pos: sizeof(loff_t) * 8 - 7;
+ int is_pneigh, bucket;
};
-static __inline__ struct neighbour *neigh_get_bucket(loff_t *pos)
+static __inline__ struct neighbour *neigh_get_bucket(struct seq_file *seq,
+ loff_t *pos)
{
struct neighbour *n = NULL;
- struct arp_iter_state* state = (struct arp_iter_state *)pos;
- loff_t l = state->pos;
- int i, bucket = state->bucket;
+ struct arp_iter_state* state = seq->private;
+ loff_t l = *pos;
+ int i;
- for (; bucket <= NEIGH_HASHMASK; ++bucket)
- for (i = 0, n = arp_tbl.hash_buckets[bucket]; n;
+ for (; state->bucket <= NEIGH_HASHMASK; ++state->bucket)
+ for (i = 0, n = arp_tbl.hash_buckets[state->bucket]; n;
++i, n = n->next)
/* Do not confuse users "arp -a" with magic entries */
if ((n->nud_state & ~NUD_NOARP) && !l--) {
- state->pos = i;
- state->bucket = bucket;
+ *pos = i;
goto out;
}
out:
return n;
}
-static __inline__ struct pneigh_entry *pneigh_get_bucket(loff_t *pos)
+static __inline__ struct pneigh_entry *pneigh_get_bucket(struct seq_file *seq,
+ loff_t *pos)
{
struct pneigh_entry *n = NULL;
- struct arp_iter_state* state = (struct arp_iter_state *)pos;
- loff_t l = state->pos;
- int i, bucket = state->bucket;
+ struct arp_iter_state* state = seq->private;
+ loff_t l = *pos;
+ int i;
- for (; bucket <= PNEIGH_HASHMASK; ++bucket)
- for (i = 0, n = arp_tbl.phash_buckets[bucket]; n;
+ for (; state->bucket <= PNEIGH_HASHMASK; ++state->bucket)
+ for (i = 0, n = arp_tbl.phash_buckets[state->bucket]; n;
++i, n = n->next)
if (!l--) {
- state->pos = i;
- state->bucket = bucket;
+ *pos = i;
goto out;
}
out:
@@ -114,18 +112,16 @@
static __inline__ void *arp_get_bucket(struct seq_file *seq, loff_t *pos)
{
- void *rc = neigh_get_bucket(pos);
+ void *rc = neigh_get_bucket(seq, pos);
if (!rc) {
- struct arp_iter_state* state = (struct arp_iter_state *)pos;
+ struct arp_iter_state* state = seq->private;
read_unlock_bh(&arp_tbl.lock);
state->is_pneigh = 1;
state->bucket = 0;
- state->pos = 0;
- /* HACK: till there is state we can pass to seq_show... */
- seq->private = (void *)1;
- rc = pneigh_get_bucket(pos);
+ *pos = 0;
+ rc = pneigh_get_bucket(seq, pos);
}
return rc;
}
@@ -146,33 +142,31 @@
goto out;
}
- state = (struct arp_iter_state *)pos;
+ state = seq->private;
if (!state->is_pneigh) {
struct neighbour *n = v;
rc = n = n->next;
if (n)
goto out;
- state->pos = 0;
+ *pos = 0;
++state->bucket;
- rc = neigh_get_bucket(pos);
+ rc = neigh_get_bucket(seq, pos);
if (rc)
goto out;
read_unlock_bh(&arp_tbl.lock);
- /* HACK: till there is state we can pass to seq_show... */
- seq->private = (void *)1;
state->is_pneigh = 1;
state->bucket = 0;
- state->pos = 0;
- rc = pneigh_get_bucket(pos);
+ *pos = 0;
+ rc = pneigh_get_bucket(seq, pos);
} else {
struct pneigh_entry *pn = v;
pn = pn->next;
if (!pn) {
++state->bucket;
- state->pos = 0;
- pn = pneigh_get_bucket(pos);
+ *pos = 0;
+ pn = pneigh_get_bucket(seq, pos);
}
rc = pn;
}
@@ -183,7 +177,9 @@
static void arp_seq_stop(struct seq_file *seq, void *v)
{
- if (!seq->private)
+ struct arp_iter_state* state = seq->private;
+
+ if (!state->is_pneigh)
read_unlock_bh(&arp_tbl.lock);
}
@@ -241,7 +237,9 @@
seq_puts(seq, "IP address HW type Flags "
"HW address Mask Device\n");
else {
- if (seq->private)
+ struct arp_iter_state* state = seq->private;
+
+ if (state->is_pneigh)
arp_format_pneigh_entry(seq, v);
else
arp_format_neigh_entry(seq, v);
@@ -405,7 +403,35 @@
static int arp_seq_open(struct inode *inode, struct file *file)
{
- return seq_open(file, &arp_seq_ops);
+ struct seq_file *seq;
+ int rc = -ENOMEM;
+ struct arp_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
+
+ if (!s)
+ goto out;
+
+ rc = seq_open(file, &arp_seq_ops);
+ if (rc)
+ goto out_kfree;
+
+ seq = file->private_data;
+ seq->private = s;
+ memset(s, 0, sizeof(*s));
+out:
+ return rc;
+out_kfree:
+ kfree(s);
+ goto out;
+}
+
+static int arp_seq_release(struct inode *inode, struct file *file)
+{
+ struct seq_file *seq = (struct seq_file *)file->private_data;
+
+ kfree(seq->private);
+ seq->private = NULL;
+
+ return seq_release(inode, file);
}
static int fib_seq_open(struct inode *inode, struct file *file)
@@ -422,7 +448,7 @@
.open = arp_seq_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = seq_release,
+ .release = arp_seq_release,
};
static struct file_operations fib_seq_fops = {
===================================================================
This BitKeeper patch contains the following changesets:
1.860
## Wrapped with gzip_uu ##
begin 664 bkpatch22554
M'XL(`%5(KCT``\U6;7/:.!#^;/V*O>G,#1!>)+\#1Z9IRR5,7II))I^N-Q['
MB-@38U%;<-.6^^^WDH"\0-.CEP^G9+Q&J]U]GD<KP1NXJ7C9L^)DRLD;.!&5
M[%F)*'@BLT7<3L2T?5NBXTH(='12,>6==Z>=@LN6W?8(>BYCF:2PX&75LUC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R^AT>'4Q/$.)P(PU675L[@1^9XBYU&!U*85!S'A14T":
M\*NJ9.:4RCJT3!Z'1O>3DANVN,Y<S`-0T1LIHG$LX[[V/WQ982F<FO)II3:R
MJ0[N`W(LA:E[B(G+>5F@"GK"U,)I;6L:T0.%OQ'#ZBY4RJV1ESSG<<77MUU6
MB#$JIDUS?5,:U=6S3K[MW@\$O'UAUG?Q_+3!]XAO?9O_Q<W9F1'>D'P,=@5/
M(\+F=O%64/VBC=5>K;(&STDV'W[&)RE/[JOY=.#0<3>83&+R#S;`HB$A#```
`
end
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Thu, 17 Oct 2002 02:23:49 -0300
master.kernel.org:/home/acme/BK/net-2.5
Pulled, thanks.
It is extremely fortunate that all this discussion about
seq_file proper usage has happened
Indeed :)