From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Nathan Fontenot <nfont@austin.ibm.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Store sysfs dirent structs in rbtree
Date: Thu, 24 Jun 2010 20:04:24 +0200 [thread overview]
Message-ID: <20100624200424.0a7d3a57@gondolin> (raw)
In-Reply-To: <4C22C944.4040700@austin.ibm.com>
On Wed, 23 Jun 2010 21:56:04 -0500,
Nathan Fontenot <nfont@austin.ibm.com> wrote:
> +static void sysfs_dirent_insert(struct sysfs_dirent *sd)
> +{
> + struct sysfs_dirent *parent_sd = sd->s_parent;
> + struct sysfs_dirent *d;
> + struct rb_node **p = &parent_sd->s_dir.rb_root.rb_node;
> + struct rb_node *parent = NULL;
> +
> + while (*p) {
> + int cmp_val;
> + parent = *p;
> + d = to_sysfs_dirent(parent);
> +
> + cmp_val = strcmp(d->s_name, sd->s_name);
> + if (cmp_val < 0)
> + p = &parent->rb_left;
> + if (cmp_val > 0)
> + p = &parent->rb_right;
> + }
> +
> + rb_link_node(&sd->s_dir.rb_node, parent, p);
> + rb_insert_color(&sd->s_dir.rb_node, &parent_sd->s_dir.rb_root);
> +}
This will run into trouble if you have duplicate names in different
namespaces. You won't see it with your patch though, since...
> @@ -536,14 +572,24 @@
> const void *ns,
> const unsigned char *name)
> {
> - struct sysfs_dirent *sd;
> -
> - for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) {
> - if (ns && sd->s_ns && (sd->s_ns != ns))
> - continue;
> - if (!strcmp(sd->s_name, name))
> - return sd;
> + struct sysfs_dirent *d;
> + struct rb_node **p = &parent_sd->s_dir.rb_root.rb_node;
> + struct rb_node *parent = NULL;
> +
> + while (*p) {
> + int cmp_val;
> + parent = *p;
> + d = to_sysfs_dirent(parent);
> +
> + cmp_val = strcmp(d->s_name, name);
> + if (cmp_val == 0)
> + return d;
> + else if (cmp_val < 0)
> + p = &parent->rb_left;
> + else /* (cmp_val > 0) */
> + p = &parent->rb_right;
> }
> +
> return NULL;
> }
...you removed the namespace check down here.
next prev parent reply other threads:[~2010-06-24 18:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-24 2:56 [PATCH] Store sysfs dirent structs in rbtree Nathan Fontenot
2010-06-24 18:04 ` Cornelia Huck [this message]
2010-06-25 1:58 ` Nathan Fontenot
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=20100624200424.0a7d3a57@gondolin \
--to=cornelia.huck@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nfont@austin.ibm.com \
/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