linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: <linux-kernel@vger.kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>, <netdev@vger.kernel.org>,
	Lucian Adrian Grijincu <lucian.grijincu@gmail.com>,
	Damien Millescamps <damien.millescamps@6wind.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 26/29] sysctl: Move sysctl_check_dups into insert_header
Date: Thu, 26 Jan 2012 20:52:02 -0800	[thread overview]
Message-ID: <1327639925-12920-26-git-send-email-ebiederm@xmission.com> (raw)
In-Reply-To: <m1pqe5ah3z.fsf@fess.ebiederm.org>

Simplify the callers of insert_header by removing explicit calls to check
for duplicates and instead have insert_header do the work.

This makes the code slightly more maintainable by enabling changes to
data structures where the insertion of new entries without duplicate
suppression is not possible.

There is not always a convenient path string where insert_header
is called so modify sysctl_check_dups to use sysctl_print_dir
when printing the full path when a duplicate is discovered.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 fs/proc/proc_sysctl.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index e0d3e7e..160d578 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -52,6 +52,7 @@ static int sysctl_follow_link(struct ctl_table_header **phead,
 	struct ctl_table **pentry, struct nsproxy *namespaces);
 static int insert_links(struct ctl_table_header *head);
 static void put_links(struct ctl_table_header *header);
+static int sysctl_check_dups(struct ctl_dir *dir, struct ctl_table *table);
 
 static void sysctl_print_dir(struct ctl_dir *dir)
 {
@@ -123,6 +124,10 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
 {
 	int err;
 
+	err = sysctl_check_dups(dir, header->ctl_table);
+	if (err)
+		return err;
+
 	dir->header.nreg++;
 	header->parent = dir;
 	err = insert_links(header);
@@ -891,7 +896,7 @@ static int sysctl_follow_link(struct ctl_table_header **phead,
 	return ret;
 }
 
-static int sysctl_check_table_dups(const char *path, struct ctl_table *old,
+static int sysctl_check_table_dups(struct ctl_dir *dir, struct ctl_table *old,
 	struct ctl_table *table)
 {
 	struct ctl_table *entry, *test;
@@ -900,8 +905,9 @@ static int sysctl_check_table_dups(const char *path, struct ctl_table *old,
 	for (entry = old; entry->procname; entry++) {
 		for (test = table; test->procname; test++) {
 			if (strcmp(entry->procname, test->procname) == 0) {
-				printk(KERN_ERR "sysctl duplicate entry: %s/%s\n",
-					path, test->procname);
+				printk(KERN_ERR "sysctl duplicate entry: ");
+				sysctl_print_dir(dir);
+				printk(KERN_CONT "/%s\n", test->procname);
 				error = -EEXIST;
 			}
 		}
@@ -909,8 +915,7 @@ static int sysctl_check_table_dups(const char *path, struct ctl_table *old,
 	return error;
 }
 
-static int sysctl_check_dups(struct ctl_dir *dir,
-	const char *path, struct ctl_table *table)
+static int sysctl_check_dups(struct ctl_dir *dir, struct ctl_table *table)
 {
 	struct ctl_table_set *set;
 	struct ctl_table_header *head;
@@ -922,7 +927,7 @@ static int sysctl_check_dups(struct ctl_dir *dir,
 			continue;
 		if (head->parent != dir)
 			continue;
-		error = sysctl_check_table_dups(path, head->ctl_table, table);
+		error = sysctl_check_table_dups(dir, head->ctl_table, table);
 	}
 	return error;
 }
@@ -1166,9 +1171,6 @@ struct ctl_table_header *__register_sysctl_table(
 	}
 
 	spin_lock(&sysctl_lock);
-	if (sysctl_check_dups(dir, path, table))
-		goto fail_put_dir_locked;
-
 	if (insert_header(dir, header))
 		goto fail_put_dir_locked;
 
-- 
1.7.2.5


  parent reply	other threads:[~2012-01-27  4:52 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-27  4:45 [Review][PATCH][0/29] sysctl rewrite for speed and clarity Eric W. Biederman
2012-01-27  4:49 ` [PATCH 01/29] sysctl: remove impossible condition check Eric W. Biederman
2012-01-27  4:49 ` [PATCH 02/29] sysctl: Consolidate !CONFIG_SYSCTL handling Eric W. Biederman
2012-01-27  4:49 ` [PATCH 03/29] sysctl: Register the base sysctl table like any other sysctl table Eric W. Biederman
2012-01-27  4:49 ` [PATCH 04/29] sysctl: Move the implementation into fs/proc/proc_sysctl.c Eric W. Biederman
2012-01-27  4:49 ` [PATCH 05/29] sysctl: Make the directories have nlink == 1 Eric W. Biederman
2012-01-27  4:49 ` [PATCH 06/29] sysctl: Implement retire_sysctl_set Eric W. Biederman
2012-01-27  4:49 ` [PATCH 07/29] sysctl: Remove the unnecessary sysctl_set parent concept Eric W. Biederman
2012-01-27  4:49 ` [PATCH 08/29] sysctl: Create local copies of directory names used in paths Eric W. Biederman
2012-01-27  4:49 ` [PATCH 09/29] sysctl: Add support for register sysctl tables with a normal cstring path Eric W. Biederman
2012-01-27  4:49 ` [PATCH 10/29] sysctl: Add ctl_table chains into cstring paths Eric W. Biederman
2012-01-27  4:49 ` [PATCH 11/29] sysctl: register only tables of sysctl files Eric W. Biederman
2012-01-27  4:49 ` [PATCH 12/29] sysctl: Improve the sysctl sanity checks Eric W. Biederman
2012-01-27  4:49 ` [PATCH 13/29] sysctl: Remove the now unused ctl_table parent field Eric W. Biederman
2012-01-27  4:49 ` [PATCH 14/29] sysctl: A more obvious version of grab_header Eric W. Biederman
2012-01-27  4:49 ` [PATCH 15/29] sysctl: Initial support for auto-unregistering sysctl tables Eric W. Biederman
2012-01-27  4:49 ` [PATCH 16/29] sysctl: Factor out init_header from __register_sysctl_paths Eric W. Biederman
2012-01-27  4:49 ` [PATCH 17/29] sysctl: Factor out insert_header and erase_header Eric W. Biederman
2012-01-27  4:49 ` [PATCH 18/29] sysctl: Normalize the root_table data structure Eric W. Biederman
2012-01-27  4:50 ` [PATCH 19/29] sysctl: Rewrite proc_sys_lookup introducing find_entry and lookup_entry Eric W. Biederman
2012-01-27  4:50 ` [PATCH 20/29] sysctl: Rewrite proc_sys_readdir in terms of first_entry and next_entry Eric W. Biederman
2012-01-27  4:50 ` [PATCH 21/29] sysctl: Add a root pointer to ctl_table_set Eric W. Biederman
2012-01-27  4:50 ` [PATCH 22/29] sysctl: Stop requiring explicit management of sysctl directories Eric W. Biederman
2012-01-27  4:50 ` [PATCH 23/29] sysctl: Add sysctl_print_dir and use it in get_subdir Eric W. Biederman
2012-01-27  4:50 ` [PATCH 24/29] sysctl: Replace root_list with links between sysctl_table_sets Eric W. Biederman
2012-01-27  4:50 ` [PATCH 25/29] sysctl: Modify __register_sysctl_paths to take a set instead of a root and an nsproxy Eric W. Biederman
2012-01-27  4:50 ` [PATCH 26/29] sysctl: Move sysctl_check_dups into insert_header Eric W. Biederman
2012-01-27  4:50 ` [PATCH 27/29] sysctl: Make the header lists per directory Eric W. Biederman
2012-01-27  4:50 ` [PATCH 28/29] sysctl: Index sysctl directories with rbtrees Eric W. Biederman
2012-01-27  4:50 ` [PATCH 29/29] sysctl: Add register_sysctl for normal sysctl users Eric W. Biederman
2012-01-27  4:51 ` [PATCH 01/29] sysctl: remove impossible condition check Eric W. Biederman
2012-01-27  4:51 ` [PATCH 02/29] sysctl: Consolidate !CONFIG_SYSCTL handling Eric W. Biederman
2012-01-27  4:51 ` [PATCH 03/29] sysctl: Register the base sysctl table like any other sysctl table Eric W. Biederman
2012-01-27  4:51 ` [PATCH 04/29] sysctl: Move the implementation into fs/proc/proc_sysctl.c Eric W. Biederman
2012-01-27  4:51 ` [PATCH 05/29] sysctl: Make the directories have nlink == 1 Eric W. Biederman
2012-01-27  4:51 ` [PATCH 06/29] sysctl: Implement retire_sysctl_set Eric W. Biederman
2012-01-27  4:51 ` [PATCH 07/29] sysctl: Remove the unnecessary sysctl_set parent concept Eric W. Biederman
2012-01-27  4:51 ` [PATCH 08/29] sysctl: Create local copies of directory names used in paths Eric W. Biederman
2012-01-27  4:51 ` [PATCH 09/29] sysctl: Add support for register sysctl tables with a normal cstring path Eric W. Biederman
2012-01-27  4:51 ` [PATCH 10/29] sysctl: Add ctl_table chains into cstring paths Eric W. Biederman
2012-01-27  4:51 ` [PATCH 11/29] sysctl: register only tables of sysctl files Eric W. Biederman
2012-01-27  4:51 ` [PATCH 12/29] sysctl: Improve the sysctl sanity checks Eric W. Biederman
2012-01-27  4:51 ` [PATCH 13/29] sysctl: Remove the now unused ctl_table parent field Eric W. Biederman
2012-01-27  4:51 ` [PATCH 14/29] sysctl: A more obvious version of grab_header Eric W. Biederman
2012-01-27  4:51 ` [PATCH 15/29] sysctl: Initial support for auto-unregistering sysctl tables Eric W. Biederman
2012-01-27  4:51 ` [PATCH 16/29] sysctl: Factor out init_header from __register_sysctl_paths Eric W. Biederman
2012-01-27  4:51 ` [PATCH 17/29] sysctl: Factor out insert_header and erase_header Eric W. Biederman
2012-01-27  4:51 ` [PATCH 18/29] sysctl: Normalize the root_table data structure Eric W. Biederman
2012-01-29 17:36   ` Lucian Adrian Grijincu
2012-01-30  0:22     ` Eric W. Biederman
2012-01-27  4:51 ` [PATCH 19/29] sysctl: Rewrite proc_sys_lookup introducing find_entry and lookup_entry Eric W. Biederman
2012-01-29 15:49   ` Lucian Adrian Grijincu
2012-01-27  4:51 ` [PATCH 20/29] sysctl: Rewrite proc_sys_readdir in terms of first_entry and next_entry Eric W. Biederman
2012-01-27  4:51 ` [PATCH 21/29] sysctl: Add a root pointer to ctl_table_set Eric W. Biederman
2012-01-29 17:19   ` Lucian Adrian Grijincu
2012-01-27  4:51 ` [PATCH 22/29] sysctl: Stop requiring explicit management of sysctl directories Eric W. Biederman
2012-01-29 19:31   ` Lucian Adrian Grijincu
2012-01-31  4:45     ` Eric W. Biederman
2012-01-27  4:51 ` [PATCH 23/29] sysctl: Add sysctl_print_dir and use it in get_subdir Eric W. Biederman
2012-01-27  4:52 ` [PATCH 24/29] sysctl: Replace root_list with links between sysctl_table_sets Eric W. Biederman
2012-01-30  0:01   ` Lucian Adrian Grijincu
2012-01-31  3:10     ` Eric W. Biederman
2012-01-30 17:51   ` Dave Jones
2012-01-31  2:11     ` Eric W. Biederman
2012-01-31  2:13       ` Joe Perches
2012-01-27  4:52 ` [PATCH 25/29] sysctl: Modify __register_sysctl_paths to take a set instead of a root and an nsproxy Eric W. Biederman
2012-01-27  4:52 ` Eric W. Biederman [this message]
2012-01-27  4:52 ` [PATCH 27/29] sysctl: Make the header lists per directory Eric W. Biederman
2012-01-27  4:52 ` [PATCH 28/29] sysctl: Index sysctl directories with rbtrees Eric W. Biederman
2012-01-27  4:52 ` [PATCH 29/29] sysctl: Add register_sysctl for normal sysctl users Eric W. Biederman
2012-02-02  3:27 ` [Review][PATCH][0/4] sysctl bitty fixes Eric W. Biederman
2012-02-02  3:28   ` [PATCH 1/4] sysctl: An easier to read version of find_subdir Eric W. Biederman
2012-02-02  3:29   ` [PATCH 2/4] sysctl: Correct error return from get_subdir Eric W. Biederman
2012-02-02  3:29   ` [PATCH 3/4] sysctl: Comments to make the code clearer Eric W. Biederman
2012-02-02 16:28     ` Ben Hutchings
2012-02-02  3:30   ` [PATCH 4/4] sysctl: Don't call sysctl_follow_link unless we are a link Eric W. Biederman

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=1327639925-12920-26-git-send-email-ebiederm@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=damien.millescamps@6wind.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucian.grijincu@gmail.com \
    --cc=netdev@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).