Commit b2f56e55 authored by Luis Chamberlain's avatar Luis Chamberlain

proc_sysctl: move helper which creates required subdirectories

Move the code which creates the subdirectories for a ctl table
into a helper routine so to make it easier to review. Document
the goal.

This creates no functional changes.
Reviewed-by: default avatarJohn Johansen <john.johansen@canonical.com>
Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
parent 67ff3228
......@@ -1283,6 +1283,35 @@ static int insert_links(struct ctl_table_header *head)
return err;
}
/* Find the directory for the ctl_table. If one is not found create it. */
static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path)
{
const char *name, *nextname;
for (name = path; name; name = nextname) {
int namelen;
nextname = strchr(name, '/');
if (nextname) {
namelen = nextname - name;
nextname++;
} else {
namelen = strlen(name);
}
if (namelen == 0)
continue;
/*
* namelen ensures if name is "foo/bar/yay" only foo is
* registered first. We traverse as if using mkdir -p and
* return a ctl_dir for the last directory entry.
*/
dir = get_subdir(dir, name, namelen);
if (IS_ERR(dir))
break;
}
return dir;
}
/**
* __register_sysctl_table - register a leaf sysctl table
* @set: Sysctl tree to register on
......@@ -1334,7 +1363,6 @@ struct ctl_table_header *__register_sysctl_table(
{
struct ctl_table_root *root = set->dir.header.root;
struct ctl_table_header *header;
const char *name, *nextname;
struct ctl_dir *dir;
struct ctl_table *entry;
struct ctl_node *node;
......@@ -1359,29 +1387,9 @@ struct ctl_table_header *__register_sysctl_table(
dir->header.nreg++;
spin_unlock(&sysctl_lock);
/* Find the directory for the ctl_table */
for (name = path; name; name = nextname) {
int namelen;
nextname = strchr(name, '/');
if (nextname) {
namelen = nextname - name;
nextname++;
} else {
namelen = strlen(name);
}
if (namelen == 0)
continue;
/*
* namelen ensures if name is "foo/bar/yay" only foo is
* registered first. We traverse as if using mkdir -p and
* return a ctl_dir for the last directory entry.
*/
dir = get_subdir(dir, name, namelen);
dir = sysctl_mkdir_p(dir, path);
if (IS_ERR(dir))
goto fail;
}
spin_lock(&sysctl_lock);
if (insert_header(dir, header))
goto fail_put_dir_locked;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment