public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Thomas Graf <tgraf@suug.ch>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/6] rhashtable: add rhashtable_walk_prev()
Date: Thu, 19 Apr 2018 09:08:07 +1000	[thread overview]
Message-ID: <87bmegqfjc.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <20180418143501.kzvknyvgnjo7v75k@gondor.apana.org.au>

[-- Attachment #1: Type: text/plain, Size: 2148 bytes --]

On Wed, Apr 18 2018, Herbert Xu wrote:

> On Wed, Apr 18, 2018 at 04:47:02PM +1000, NeilBrown wrote:
>> rhashtable_walk_prev() returns the object returned by
>> the previous rhashtable_walk_next(), providing it is still in the
>> table (or was during this grace period).
>> This works even if rhashtable_walk_stop() and rhashtable_talk_start()
>> have been called since the last rhashtable_walk_next().
>> 
>> If there have been no calls to rhashtable_walk_next(), or if the
>> object is gone from the table, then NULL is returned.
>> 
>> This can usefully be used in a seq_file ->start() function.
>> If the pos is the same as was returned by the last ->next() call,
>> then rhashtable_walk_prev() can be used to re-establish the
>> current location in the table.  If it returns NULL, then
>> rhashtable_walk_next() should be used.
>> 
>> Signed-off-by: NeilBrown <neilb@suse.com>
>
> Can you explain the need for this function and its difference
> from the existing rhashtable_walk_peek?

The need is essentially the same as the need for
rhashtable_walk_peek().  The difference is that the actual behaviour can
be documented briefly (and so understood easily) without enumerating
multiple special cases.
rhashtable_walk_peek() is much the same as
 rhashtable_walk_prev() ?: rhashtable_walk_next()

The need arises when you need to "stop" a walk and then restart at the
same object, not the next one. i.e. the last object returned before the
"stop" wasn't acted on.
This happens with seq_file if the buffer space for ->show() is not
sufficient to format an object.  In the case, seq_file will stop() the
iteration, make more space available (either by flushing or by
reallocing) and will start again at the same location.
If the seq_file client stored the rhashtable_iter in the seq_file
private data, it can use rhasthable_walk_prev() to recover its position
if that object is still in the hash table.  If it isn't still present,
rhashtable_walk_next() can be used to get the next one.  In some cases
it can be useful for the client to know whether it got the previous one
or not.

Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2018-04-18 23:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18  6:47 [PATCH 0/6] Assorted rhashtable improvements. RESEND NeilBrown
2018-04-18  6:47 ` [PATCH 3/6] rhashtable: reset iter when rhashtable_walk_start sees new table NeilBrown
2018-04-18  6:47 ` [PATCH 2/6] rhashtable: remove incorrect comment on r{hl, hash}table_walk_enter() NeilBrown
2018-04-18 14:28   ` Herbert Xu
2018-04-18 22:56     ` NeilBrown
2018-04-19  3:22       ` Herbert Xu
2018-04-23  1:39         ` NeilBrown
2018-04-23  8:06           ` Herbert Xu
2018-04-18  6:47 ` [PATCH 1/6] rhashtable: remove outdated comments about grow_decision etc NeilBrown
2018-04-18 14:29   ` Herbert Xu
2018-04-18 23:09     ` NeilBrown
2018-04-19  1:47       ` David Miller
2018-04-23  1:41         ` NeilBrown
2018-04-18  6:47 ` [PATCH 6/6] rhashtable: add rhashtable_walk_prev() NeilBrown
2018-04-18 14:35   ` Herbert Xu
2018-04-18 23:08     ` NeilBrown [this message]
2018-04-23  8:07       ` Herbert Xu
2018-04-18  6:47 ` [PATCH 5/6] rhashtable: further improve stability of rhashtable_walk NeilBrown
2018-04-18  6:47 ` [PATCH 4/6] rhashtable: improve rhashtable_walk stability when stop/start used NeilBrown
  -- strict thread matches above, loose matches on Subject: below --
2018-04-18  6:47 [PATCH 0/6] Assorted rhashtable improvements NeilBrown
2018-04-18  6:47 ` [PATCH 6/6] rhashtable: add rhashtable_walk_prev() NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bmegqfjc.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox