@@ -2237,146 +2237,6 @@ static const struct file_operations proc_coredump_filter_operations = {
22372237};
22382238#endif
22392239
2240- /*
2241- * /proc/self:
2242- */
2243- static int proc_self_readlink (struct dentry * dentry , char __user * buffer ,
2244- int buflen )
2245- {
2246- struct pid_namespace * ns = dentry -> d_sb -> s_fs_info ;
2247- pid_t tgid = task_tgid_nr_ns (current , ns );
2248- char tmp [PROC_NUMBUF ];
2249- if (!tgid )
2250- return - ENOENT ;
2251- sprintf (tmp , "%d" , tgid );
2252- return vfs_readlink (dentry ,buffer ,buflen ,tmp );
2253- }
2254-
2255- static void * proc_self_follow_link (struct dentry * dentry , struct nameidata * nd )
2256- {
2257- struct pid_namespace * ns = dentry -> d_sb -> s_fs_info ;
2258- pid_t tgid = task_tgid_nr_ns (current , ns );
2259- char * name = ERR_PTR (- ENOENT );
2260- if (tgid ) {
2261- /* 11 for max length of signed int in decimal + NULL term */
2262- name = kmalloc (12 , GFP_KERNEL );
2263- if (!name )
2264- name = ERR_PTR (- ENOMEM );
2265- else
2266- sprintf (name , "%d" , tgid );
2267- }
2268- nd_set_link (nd , name );
2269- return NULL ;
2270- }
2271-
2272- static void proc_self_put_link (struct dentry * dentry , struct nameidata * nd ,
2273- void * cookie )
2274- {
2275- char * s = nd_get_link (nd );
2276- if (!IS_ERR (s ))
2277- kfree (s );
2278- }
2279-
2280- static const struct inode_operations proc_self_inode_operations = {
2281- .readlink = proc_self_readlink ,
2282- .follow_link = proc_self_follow_link ,
2283- .put_link = proc_self_put_link ,
2284- };
2285-
2286- /*
2287- * proc base
2288- *
2289- * These are the directory entries in the root directory of /proc
2290- * that properly belong to the /proc filesystem, as they describe
2291- * describe something that is process related.
2292- */
2293- static const struct pid_entry proc_base_stuff [] = {
2294- NOD ("self" , S_IFLNK |S_IRWXUGO ,
2295- & proc_self_inode_operations , NULL , {}),
2296- };
2297-
2298- static struct dentry * proc_base_instantiate (struct inode * dir ,
2299- struct dentry * dentry , struct task_struct * task , const void * ptr )
2300- {
2301- const struct pid_entry * p = ptr ;
2302- struct inode * inode ;
2303- struct proc_inode * ei ;
2304- struct dentry * error ;
2305-
2306- /* Allocate the inode */
2307- error = ERR_PTR (- ENOMEM );
2308- inode = new_inode (dir -> i_sb );
2309- if (!inode )
2310- goto out ;
2311-
2312- /* Initialize the inode */
2313- ei = PROC_I (inode );
2314- inode -> i_ino = get_next_ino ();
2315- inode -> i_mtime = inode -> i_atime = inode -> i_ctime = CURRENT_TIME ;
2316-
2317- /*
2318- * grab the reference to the task.
2319- */
2320- ei -> pid = get_task_pid (task , PIDTYPE_PID );
2321- if (!ei -> pid )
2322- goto out_iput ;
2323-
2324- inode -> i_mode = p -> mode ;
2325- if (S_ISDIR (inode -> i_mode ))
2326- set_nlink (inode , 2 );
2327- if (S_ISLNK (inode -> i_mode ))
2328- inode -> i_size = 64 ;
2329- if (p -> iop )
2330- inode -> i_op = p -> iop ;
2331- if (p -> fop )
2332- inode -> i_fop = p -> fop ;
2333- ei -> op = p -> op ;
2334- d_add (dentry , inode );
2335- error = NULL ;
2336- out :
2337- return error ;
2338- out_iput :
2339- iput (inode );
2340- goto out ;
2341- }
2342-
2343- static struct dentry * proc_base_lookup (struct inode * dir , struct dentry * dentry )
2344- {
2345- struct dentry * error ;
2346- struct task_struct * task = get_proc_task (dir );
2347- const struct pid_entry * p , * last ;
2348-
2349- error = ERR_PTR (- ENOENT );
2350-
2351- if (!task )
2352- goto out_no_task ;
2353-
2354- /* Lookup the directory entry */
2355- last = & proc_base_stuff [ARRAY_SIZE (proc_base_stuff ) - 1 ];
2356- for (p = proc_base_stuff ; p <= last ; p ++ ) {
2357- if (p -> len != dentry -> d_name .len )
2358- continue ;
2359- if (!memcmp (dentry -> d_name .name , p -> name , p -> len ))
2360- break ;
2361- }
2362- if (p > last )
2363- goto out ;
2364-
2365- error = proc_base_instantiate (dir , dentry , task , p );
2366-
2367- out :
2368- put_task_struct (task );
2369- out_no_task :
2370- return error ;
2371- }
2372-
2373- static int proc_base_fill_cache (struct file * filp , void * dirent ,
2374- filldir_t filldir , struct task_struct * task , const struct pid_entry * p )
2375- {
2376- return proc_fill_cache (filp , dirent , filldir , p -> name , p -> len ,
2377- proc_base_instantiate , task , p );
2378- }
2379-
23802240#ifdef CONFIG_TASK_IO_ACCOUNTING
23812241static int do_io_accounting (struct task_struct * task , char * buffer , int whole )
23822242{
@@ -2767,15 +2627,11 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
27672627
27682628struct dentry * proc_pid_lookup (struct inode * dir , struct dentry * dentry , unsigned int flags )
27692629{
2770- struct dentry * result ;
2630+ struct dentry * result = NULL ;
27712631 struct task_struct * task ;
27722632 unsigned tgid ;
27732633 struct pid_namespace * ns ;
27742634
2775- result = proc_base_lookup (dir , dentry );
2776- if (!IS_ERR (result ) || PTR_ERR (result ) != - ENOENT )
2777- goto out ;
2778-
27792635 tgid = name_to_int (dentry );
27802636 if (tgid == ~0U )
27812637 goto out ;
@@ -2838,7 +2694,7 @@ static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter ite
28382694 return iter ;
28392695}
28402696
2841- #define TGID_OFFSET (FIRST_PROCESS_ENTRY + ARRAY_SIZE(proc_base_stuff) )
2697+ #define TGID_OFFSET (FIRST_PROCESS_ENTRY)
28422698
28432699static int proc_pid_fill_cache (struct file * filp , void * dirent , filldir_t filldir ,
28442700 struct tgid_iter iter )
@@ -2872,12 +2728,6 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
28722728 if (!reaper )
28732729 goto out_no_task ;
28742730
2875- for (; nr < ARRAY_SIZE (proc_base_stuff ); filp -> f_pos ++ , nr ++ ) {
2876- const struct pid_entry * p = & proc_base_stuff [nr ];
2877- if (proc_base_fill_cache (filp , dirent , filldir , reaper , p ) < 0 )
2878- goto out ;
2879- }
2880-
28812731 ns = filp -> f_dentry -> d_sb -> s_fs_info ;
28822732 iter .task = NULL ;
28832733 iter .tgid = filp -> f_pos - TGID_OFFSET ;
0 commit comments