diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2012-01-31 00:23:52 -0500 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-02-01 22:20:57 -0500 |
commit | 60f126d93b210ae708e2a5bb4a3be2121831f2a0 (patch) | |
tree | 1ebdf75d1a8bca0122b6dcb34a7efae2a1839919 /fs/proc/proc_sysctl.c | |
parent | 0eb97f38d2bfaea289b44c5140a7b04e7b369bad (diff) |
sysctl: Comments to make the code clearer.
Document get_subdir and that find_subdir alwasy takes a reference.
Suggested-by: Lucian Adrian Grijincu <lucian.grijincu@gmail.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'fs/proc/proc_sysctl.c')
-rw-r--r-- | fs/proc/proc_sysctl.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 722ec116208d..e5601dc24088 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c | |||
@@ -73,6 +73,7 @@ static int namecmp(const char *name1, int len1, const char *name2, int len2) | |||
73 | return cmp; | 73 | return cmp; |
74 | } | 74 | } |
75 | 75 | ||
76 | /* Called under sysctl_lock */ | ||
76 | static struct ctl_table *find_entry(struct ctl_table_header **phead, | 77 | static struct ctl_table *find_entry(struct ctl_table_header **phead, |
77 | struct ctl_dir *dir, const char *name, int namelen) | 78 | struct ctl_dir *dir, const char *name, int namelen) |
78 | { | 79 | { |
@@ -864,6 +865,18 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set, | |||
864 | return new; | 865 | return new; |
865 | } | 866 | } |
866 | 867 | ||
868 | /** | ||
869 | * get_subdir - find or create a subdir with the specified name. | ||
870 | * @dir: Directory to create the subdirectory in | ||
871 | * @name: The name of the subdirectory to find or create | ||
872 | * @namelen: The length of name | ||
873 | * | ||
874 | * Takes a directory with an elevated reference count so we know that | ||
875 | * if we drop the lock the directory will not go away. Upon success | ||
876 | * the reference is moved from @dir to the returned subdirectory. | ||
877 | * Upon error an error code is returned and the reference on @dir is | ||
878 | * simply dropped. | ||
879 | */ | ||
867 | static struct ctl_dir *get_subdir(struct ctl_dir *dir, | 880 | static struct ctl_dir *get_subdir(struct ctl_dir *dir, |
868 | const char *name, int namelen) | 881 | const char *name, int namelen) |
869 | { | 882 | { |
@@ -885,12 +898,14 @@ static struct ctl_dir *get_subdir(struct ctl_dir *dir, | |||
885 | if (!new) | 898 | if (!new) |
886 | goto failed; | 899 | goto failed; |
887 | 900 | ||
901 | /* Was the subdir added while we dropped the lock? */ | ||
888 | subdir = find_subdir(dir, name, namelen); | 902 | subdir = find_subdir(dir, name, namelen); |
889 | if (!IS_ERR(subdir)) | 903 | if (!IS_ERR(subdir)) |
890 | goto found; | 904 | goto found; |
891 | if (PTR_ERR(subdir) != -ENOENT) | 905 | if (PTR_ERR(subdir) != -ENOENT) |
892 | goto failed; | 906 | goto failed; |
893 | 907 | ||
908 | /* Nope. Use the our freshly made directory entry. */ | ||
894 | err = insert_header(dir, &new->header); | 909 | err = insert_header(dir, &new->header); |
895 | subdir = ERR_PTR(err); | 910 | subdir = ERR_PTR(err); |
896 | if (err) | 911 | if (err) |
@@ -1190,6 +1205,7 @@ struct ctl_table_header *__register_sysctl_table( | |||
1190 | 1205 | ||
1191 | spin_lock(&sysctl_lock); | 1206 | spin_lock(&sysctl_lock); |
1192 | dir = &set->dir; | 1207 | dir = &set->dir; |
1208 | /* Reference moved down the diretory tree get_subdir */ | ||
1193 | dir->header.nreg++; | 1209 | dir->header.nreg++; |
1194 | spin_unlock(&sysctl_lock); | 1210 | spin_unlock(&sysctl_lock); |
1195 | 1211 | ||