From: Andrew Morton <akpm@linux-foundation.org>
To: Jeffrey Layton <jlayton@redhat.com>
Cc: hch@infradead.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
Date: Fri, 13 Apr 2007 11:42:14 -0700 [thread overview]
Message-ID: <20070413114214.cb9328f5.akpm@linux-foundation.org> (raw)
In-Reply-To: <200704112158.l3BLwunk023090@dantu.rdu.redhat.com>
On Wed, 11 Apr 2007 17:58:56 -0400
Jeffrey Layton <jlayton@redhat.com> wrote:
> A while back, Christoph mentioned that he thought that iunique ought to be
> cleaned up to use a more conventional loop construct. This patch does that,
> turning the strange goto loop into a do/while.
>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 23fc1fd..90e7587 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -689,21 +689,18 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
> struct inode *inode;
> struct hlist_head * head;
> ino_t res;
> +
> spin_lock(&inode_lock);
> -retry:
> - if (counter > max_reserved) {
> - head = inode_hashtable + hash(sb,counter);
> + do {
> + if (counter <= max_reserved)
> + counter = max_reserved + 1;
> res = counter++;
> + head = inode_hashtable + hash(sb, res);
> inode = find_inode_fast(sb, head, res);
> - if (!inode) {
> - spin_unlock(&inode_lock);
> - return res;
> - }
> - } else {
> - counter = max_reserved + 1;
> - }
> - goto retry;
> -
> + } while (inode != NULL);
> + spin_unlock(&inode_lock);
> +
> + return res;
> }
>
hm.
ino_t iunique(struct super_block *sb, ino_t max_reserved)
{
static ino_t counter;
struct inode *inode;
struct hlist_head * head;
ino_t res;
spin_lock(&inode_lock);
do {
if (counter <= max_reserved)
counter = max_reserved + 1;
res = counter++;
head = inode_hashtable + hash(sb, res);
inode = find_inode_fast(sb, head, res);
} while (inode != NULL);
spin_unlock(&inode_lock);
return res;
}
The counter-vs-max_reserved test can be moved outside the loop, can't it?
Shouldn't counter be per-sb?
next prev parent reply other threads:[~2007-04-13 18:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-11 21:58 [PATCH] make iunique use a do/while loop rather than its obscure goto loop Jeffrey Layton
2007-04-13 18:42 ` Andrew Morton [this message]
2007-04-13 19:08 ` Jeff Layton
2007-04-13 19:55 ` Andrew Morton
2007-06-23 8:08 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2007-01-30 15:45 Jeffrey Layton
2007-01-31 8:16 ` Christoph Hellwig
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=20070413114214.cb9328f5.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).