Thread (23 messages) 23 messages, 8 authors, 2016-02-12

Re: [PATCH 2/8] kernfs: implement kernfs_walk_and_get()

From: Geert Uytterhoeven <hidden>
Date: 2016-01-15 12:29:12
Also in: cgroups, lkml, netfilter-devel

On Mon, Dec 7, 2015 at 11:38 PM, Tejun Heo [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Implement kernfs_walk_and_get() which is similar to
kernfs_find_and_get() but can walk a path instead of just a name.

v2: Use strlcpy() instead of strlen() + memcpy() as suggested by
    David.

Signed-off-by: Tejun Heo <redacted>
Acked-by: Greg Kroah-Hartman <redacted>
Cc: David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
---
 fs/kernfs/dir.c        | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/kernfs.h | 12 ++++++++++++
 2 files changed, 58 insertions(+)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 91e0045..742bf4a 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -694,6 +694,29 @@ static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
        return NULL;
 }

+static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
+                                         const unsigned char *path,
+                                         const void *ns)
+{
+       static char path_buf[PATH_MAX]; /* protected by kernfs_mutex */
This is showing up in bloat-o-meter as increasing kernel size by 4 KiB.
+       size_t len = strlcpy(path_buf, path, PATH_MAX);
The full input string is copied because strsep() replaces the delimiters by
zeroes?
Can this be handled in some other way?
+       char *p = path_buf;
+       char *name;
+
+       lockdep_assert_held(&kernfs_mutex);
+
+       if (len >= PATH_MAX)
+               return NULL;
+
+       while ((name = strsep(&p, "/")) && parent) {
+               if (*name == '\0')
+                       continue;
+               parent = kernfs_find_ns(parent, name, ns);
+       }
+
+       return parent;
+}
Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help