Received: by 10.213.65.68 with SMTP id h4csp775237imn; Tue, 27 Mar 2018 08:32:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELuHDnJWkQVwMMH+JKYMMuTSI01AUzBZPtBFJrabjRm0PewF+TLQXTeaWi+3rUQvD2sUx4Vl X-Received: by 2002:a17:902:127:: with SMTP id 36-v6mr45677478plb.194.1522164770802; Tue, 27 Mar 2018 08:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522164770; cv=none; d=google.com; s=arc-20160816; b=pbi8bxoXkr68nAqhIIuAaK8LQjhOaepoHfiYN6621bl6EXzrnKWa1IKWdPz129iE+I BfJyl/vrAsDVzv6bKY1uN12yiISXfuiIBDqpyIMa920t6gYF4sW8KROnqK5OabmsSYHn 4+rR8DECtf1Za91nZ1CZLrggOYy87zkRmRu6nS4xn35qBmTn2331wjAVhMflI8npb/D/ kZ+YBEX7SbjUG4clZENMYLzYX5hakr9w42u5EWo2QG0vcSJ4c2/XnIDPLNB3oYkt7D4N KM1Cz8gqyXN0NUj9xaz/7fFkhbXKViCye7JVOGhUSfZ5b4cDqGbteJAPYFCGzGN59PME FgGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=GZ0Nqvz368njHR2kbGxabhJYFBWjaa5mkrauKESYV1M=; b=e6I5shHofZg7mTPc1F9aIFX1ci5zcnkpjWhk/wyZ86Jn61e3BqvNQUZTAq73l20Akl EANTOCWfESxwkw14/sNuGvoUl8sfPAhlkHvyWpFQRAQu0E3Lgmq02C+m653kILsMlpaw 3hggPL6ggiPb8SbUQPeIv/R85Rm3Tife0ki/UgnOMzb1U3L8xQ5zWNP4bRrNe+AyOXjY O1OCTdmkdvEQpxXOUYeiDyAYTcfgVe6q5L/kYLfaX8UG+2uZC0LHBGQq6OdXdc+kAbg3 cAjgC1vlHXPOxEPovRwR7pjIRnZc2awl1p56uP6sO3Zo/M4p5A0KMXMf03k+2izXjTET qNUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b92-v6si1517310plb.514.2018.03.27.08.32.35; Tue, 27 Mar 2018 08:32:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752578AbeC0Paz (ORCPT + 99 others); Tue, 27 Mar 2018 11:30:55 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:45674 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752088AbeC0Pay (ORCPT ); Tue, 27 Mar 2018 11:30:54 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.84_2 #2 (Debian)) id 1f0qYe-0007I8-Hd; Tue, 27 Mar 2018 23:30:44 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1f0qYY-0003dG-BY; Tue, 27 Mar 2018 23:30:38 +0800 Date: Tue, 27 Mar 2018 23:30:38 +0800 From: Herbert Xu To: NeilBrown Cc: Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Herbert Subject: Re: [PATCH 1/6] rhashtable: improve documentation for rhashtable_walk_peek() Message-ID: <20180327153038.GA13868@gondor.apana.org.au> References: <152210688405.11435.13010923693146415942.stgit@noble> <152210718418.11435.11573013181393548255.stgit@noble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <152210718418.11435.11573013181393548255.stgit@noble> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 27, 2018 at 10:33:04AM +1100, NeilBrown wrote: > The documentation for rhashtable_walk_peek() wrong. It claims to > return the *next* entry, whereas it in fact returns the *previous* > entry. > However if no entries have yet been returned - or if the iterator > was reset due to a resize event, then rhashtable_walk_peek() > *does* return the next entry, but also advances the iterator. > > I suspect that this interface should be discarded and the one user > should be changed to not require it. Possibly this patch should be > seen as a first step in that conversation. > > This patch mostly corrects the documentation, but does make a > small code change so that the documentation can be correct without > listing too many special cases. I don't think the one user will > be affected by the code change. > > Signed-off-by: NeilBrown We should cc Tom Herbert too since he wrote this code. > --- > lib/rhashtable.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/lib/rhashtable.c b/lib/rhashtable.c > index 3825c30aaa36..24a57ca494cb 100644 > --- a/lib/rhashtable.c > +++ b/lib/rhashtable.c > @@ -853,13 +853,17 @@ void *rhashtable_walk_next(struct rhashtable_iter *iter) > EXPORT_SYMBOL_GPL(rhashtable_walk_next); > > /** > - * rhashtable_walk_peek - Return the next object but don't advance the iterator > + * rhashtable_walk_peek - Return the previously returned object without advancing the iterator > * @iter: Hash table iterator > * > - * Returns the next object or NULL when the end of the table is reached. > + * Returns the last object returned, or NULL if no object has yet been returned. > + * If the previously returned object has since been removed, then some other arbitrary > + * object maybe returned, or possibly NULL will be returned. In that case, the > + * iterator might be advanced. > * > * Returns -EAGAIN if resize event occurred. Note that the iterator > - * will rewind back to the beginning and you may continue to use it. > + * will rewind back to the beginning and rhashtable_walk_next() should be > + * used to get the next object. > */ > void *rhashtable_walk_peek(struct rhashtable_iter *iter) > { > @@ -880,7 +884,12 @@ void *rhashtable_walk_peek(struct rhashtable_iter *iter) > * the table hasn't changed. > */ > iter->skip--; > - } > + } else > + /* ->skip is only zero after rhashtable_walk_start() > + * or when the iterator is reset. In this case there > + * is no previous object to return. > + */ > + return NULL; > > return __rhashtable_walk_find_next(iter); > } > > -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt