Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1610752imm; Wed, 6 Jun 2018 20:03:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKeN0G0EXyOBttGU+svS2Fl7mhnRTCVPEyniYA0+KPE9jWypBTN/fd7I6oTkXEglcQJ8END X-Received: by 2002:a62:e903:: with SMTP id j3-v6mr108693pfh.196.1528340616735; Wed, 06 Jun 2018 20:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528340616; cv=none; d=google.com; s=arc-20160816; b=ipBhP4H78EtY4uUpItlAwqlB48Etg1MZ3py5kH26+og9yKDmfb7uwcSvv/ojnnYmx+ 1bNSLIgfqYi80fb3e50aGs+ds8SYWlSlT5S2Fv3jNFNWwGxOoblmudYb9MizsxbUMpCO ogbFz4p0I7XcAEoqiMDy+oMLoZTe33lO0ST0QsytXTtswDV2gpWKPGg/G6iXBYXFW9dL 0s5vrr77ZFIeGP+6JY5FgqhnkhRNXkSiAaEbEB9wNkzRjhtjbQIPJdTrsgyR00w1Uc+v hiZsGll49kWvAHBa5AIsPNidQebxfPMKrNh3EIvEZelo7lrCGrFuYmym1Z0e1fIT5qA+ ke9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from:arc-authentication-results; bh=qaDwSKIvR3j/VHBtY4FgkZXbFgqNTmG5WaAGoq+BKHU=; b=NxCQJmjLk7XJMyTJJJyou7/EsZbm+UAzTBltlTpZ+OFukDX0L4vEqaZ4XLCTgKHc2N GtYp/ni5igNv3wTYf2CsaewXWN6Wvm1t85006x6CzfbJGZMs8Bwv16QGnY90GyfFM1Bt xYlWAJtNVw8FBFeMcKdW01Is9KWodpcGYKlJ3a5+HklkIVDsl7jvcfHId1oD1cJOYSAw XIoihJO/iCQPIkhhF2cF182mdjjbINgrxiRvayq1aHT8MC7NVzjc8ORTzRFuCfuhT4gO FnBRd473AqeLdzn0ZGZ5cJWPfAlvUs+QZUzZUYwQXWEZxPTrew/BrUsdEz4lwlS8ZIAd TO5Q== 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 43-v6si54611186plb.511.2018.06.06.20.02.52; Wed, 06 Jun 2018 20:03:36 -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 S932338AbeFGCqk (ORCPT + 99 others); Wed, 6 Jun 2018 22:46:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:50852 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753471AbeFGCqj (ORCPT ); Wed, 6 Jun 2018 22:46:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2F3DFAD0B; Thu, 7 Jun 2018 02:46:38 +0000 (UTC) From: NeilBrown To: Tom Herbert Date: Thu, 07 Jun 2018 12:46:30 +1000 Cc: Herbert Xu , Thomas Graf , Linux Kernel Network Developers , LKML , Tom Herbert Subject: [PATCH - RFC] rhashtable: implement rhashtable_walk_peek() using rhashtable_walk_last_seen() In-Reply-To: <871sdjnwkr.fsf@notabene.neil.brown.name> References: <152782754287.30340.4395718227884933670.stgit@noble> <152782824964.30340.6329146982899668633.stgit@noble> <20180602154851.pfy4wryezuhxp76v@gondor.apana.org.au> <87y3fvpf40.fsf@notabene.neil.brown.name> <87sh63pakb.fsf@notabene.neil.brown.name> <87r2lmnj2c.fsf@notabene.neil.brown.name> <87in6wo636.fsf@notabene.neil.brown.name> <871sdjnwkr.fsf@notabene.neil.brown.name> Message-ID: <87y3frmhyx.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable rhashtable_walk_last_seen() does most of the work that rhashtable_walk_peek() needs done, so use it. Also update the documentation for rhashtable_walk_peek() to clarify the expected use case. Signed-off-by: NeilBrown =2D-- lib/rhashtable.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 45f2554399a5..30bb9ead15f4 100644 =2D-- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -916,36 +916,34 @@ void *rhashtable_walk_next(struct rhashtable_iter *it= er) EXPORT_SYMBOL_GPL(rhashtable_walk_next); =20 /** =2D * rhashtable_walk_peek - Return the next object but don't advance the i= terator + * rhashtable_walk_peek - Return the next object to use in an interrupted = walk * @iter: Hash table iterator * =2D * Returns the next object or NULL when the end of the table is reached. + * Returns the "current" object or NULL when the end of the table is reach= ed. + * When an rhashtable_walk is interrupted with rhashtable_walk_stop(), + * it is often because an object was found that could not be processed + * immediately, possible because there is no more space to encode details + * of the object (e.g. when producing a seq_file from the table). + * When the walk is restarted, the same object needs to be processed again, + * if possible. The object might have been removed from the table while + * the walk was paused, so it might not be available. In that case, the + * normal "next" object should be treated as "current". * =2D * Returns -EAGAIN if resize event occurred. Note that the iterator + * To support this common case, rhashtable_walk_peek() returns the + * appropriate object to process after an interrupted walk, either the + * one that was most recently returned, or if that doesn't exist - the + * next one. + * + * Returns -EAGAIN if resize event occurred. In that case the iterator * will rewind back to the beginning and you may continue to use it. */ void *rhashtable_walk_peek(struct rhashtable_iter *iter) { =2D struct rhlist_head *list =3D iter->list; =2D struct rhashtable *ht =3D iter->ht; =2D struct rhash_head *p =3D iter->p; + void *ret =3D rhashtable_walk_last_seen(iter); =20 =2D if (p) =2D return rht_obj(ht, ht->rhlist ? &list->rhead : p); =2D =2D /* No object found in current iter, find next one in the table. */ =2D =2D if (iter->skip) { =2D /* A nonzero skip value points to the next entry in the table =2D * beyond that last one that was found. Decrement skip so =2D * we find the current value. __rhashtable_walk_find_next =2D * will restore the original value of skip assuming that =2D * the table hasn't changed. =2D */ =2D iter->skip--; =2D } =2D =2D return __rhashtable_walk_find_next(iter); + if (!ret) + ret =3D rhashtable_walk_next(iter); + return ret; } EXPORT_SYMBOL_GPL(rhashtable_walk_peek); =20 =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlsYnIcACgkQOeye3VZi gbl6PBAAp9ntBGKzD9pALbngdpTBLv+eK9ukpkhqJYlfZ6kwQsl272NQYzzUYHsv 4OHkieUMt+8odh+eP8ucymUDCo3wad4dazhXih4qI4bwjn0UQyKxtWZxjJaVGAZX ojgXevPqsFnohOteLwbDbZiW+8DlRO/DDUZFVCKOn9SoCUjFjbLblrTklV+hlcWn PuuEsBdHEYVOZYvsp9pAlPu8Yh9+ZLx7vhWEZJbMpoubHp4Y0OoLmWVZEooEKVr1 Ot6ABTxze3zwJKr8QrWHvsiKTfgZzPxmbK/Ux8X29DR9tyUFh3i4i5oSUQ26h9o4 uWiTNERIFV/uR89XDw7MvtRyvTFdkux4IkZkf0NX3KUijADVED4DywfbOuz/03ul 8aL/v8UrZvb8zzLubucGA2Kod2HEGy9UgWN6V5ylRLc5yRGLEND+Pkto6psHWW6q 2UlE1/WnPYbRSVtry3sAxtAAb2VsRuAZHYPkT6aXWAoY/FfEVnL0GoloifY3RXKd /YBeXLTSkDeTbYBMhn/4TjM17pxLFbdWPD6Xui7nou6lY/mEzu7hsUFgEOks7IxB PGsdDDjp3nGhoPvkjMOGz8vjMhkxZ4E9K+mc3CyBgURm6e1KhQ9DKpKr33mxHOgW g7k0K4KzDXaIEV+wYS8YsbqRuRQO37nDwwPEsFDfg0U4OgWt6fM= =90TW -----END PGP SIGNATURE----- --=-=-=--