.. | .. |
---|
1882 | 1882 | put_pid(pid); |
---|
1883 | 1883 | } |
---|
1884 | 1884 | |
---|
1885 | | -struct inode *proc_pid_make_inode(struct super_block * sb, |
---|
| 1885 | +struct inode *proc_pid_make_inode(struct super_block *sb, |
---|
1886 | 1886 | struct task_struct *task, umode_t mode) |
---|
1887 | 1887 | { |
---|
1888 | 1888 | struct inode * inode; |
---|
.. | .. |
---|
1911 | 1911 | |
---|
1912 | 1912 | /* Let the pid remember us for quick removal */ |
---|
1913 | 1913 | ei->pid = pid; |
---|
1914 | | - if (S_ISDIR(mode)) { |
---|
1915 | | - spin_lock(&pid->lock); |
---|
1916 | | - hlist_add_head_rcu(&ei->sibling_inodes, &pid->inodes); |
---|
1917 | | - spin_unlock(&pid->lock); |
---|
1918 | | - } |
---|
1919 | 1914 | |
---|
1920 | 1915 | task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid); |
---|
1921 | 1916 | security_task_to_inode(task, inode); |
---|
.. | .. |
---|
1926 | 1921 | out_unlock: |
---|
1927 | 1922 | iput(inode); |
---|
1928 | 1923 | return NULL; |
---|
| 1924 | +} |
---|
| 1925 | + |
---|
| 1926 | +/* |
---|
| 1927 | + * Generating an inode and adding it into @pid->inodes, so that task will |
---|
| 1928 | + * invalidate inode's dentry before being released. |
---|
| 1929 | + * |
---|
| 1930 | + * This helper is used for creating dir-type entries under '/proc' and |
---|
| 1931 | + * '/proc/<tgid>/task'. Other entries(eg. fd, stat) under '/proc/<tgid>' |
---|
| 1932 | + * can be released by invalidating '/proc/<tgid>' dentry. |
---|
| 1933 | + * In theory, dentries under '/proc/<tgid>/task' can also be released by |
---|
| 1934 | + * invalidating '/proc/<tgid>' dentry, we reserve it to handle single |
---|
| 1935 | + * thread exiting situation: Any one of threads should invalidate its |
---|
| 1936 | + * '/proc/<tgid>/task/<pid>' dentry before released. |
---|
| 1937 | + */ |
---|
| 1938 | +static struct inode *proc_pid_make_base_inode(struct super_block *sb, |
---|
| 1939 | + struct task_struct *task, umode_t mode) |
---|
| 1940 | +{ |
---|
| 1941 | + struct inode *inode; |
---|
| 1942 | + struct proc_inode *ei; |
---|
| 1943 | + struct pid *pid; |
---|
| 1944 | + |
---|
| 1945 | + inode = proc_pid_make_inode(sb, task, mode); |
---|
| 1946 | + if (!inode) |
---|
| 1947 | + return NULL; |
---|
| 1948 | + |
---|
| 1949 | + /* Let proc_flush_pid find this directory inode */ |
---|
| 1950 | + ei = PROC_I(inode); |
---|
| 1951 | + pid = ei->pid; |
---|
| 1952 | + spin_lock(&pid->lock); |
---|
| 1953 | + hlist_add_head_rcu(&ei->sibling_inodes, &pid->inodes); |
---|
| 1954 | + spin_unlock(&pid->lock); |
---|
| 1955 | + |
---|
| 1956 | + return inode; |
---|
1929 | 1957 | } |
---|
1930 | 1958 | |
---|
1931 | 1959 | int pid_getattr(const struct path *path, struct kstat *stat, |
---|
.. | .. |
---|
3345 | 3373 | { |
---|
3346 | 3374 | struct inode *inode; |
---|
3347 | 3375 | |
---|
3348 | | - inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); |
---|
| 3376 | + inode = proc_pid_make_base_inode(dentry->d_sb, task, |
---|
| 3377 | + S_IFDIR | S_IRUGO | S_IXUGO); |
---|
3349 | 3378 | if (!inode) |
---|
3350 | 3379 | return ERR_PTR(-ENOENT); |
---|
3351 | 3380 | |
---|
.. | .. |
---|
3510 | 3539 | } |
---|
3511 | 3540 | |
---|
3512 | 3541 | static const struct inode_operations proc_tid_comm_inode_operations = { |
---|
3513 | | - .permission = proc_tid_comm_permission, |
---|
| 3542 | + .setattr = proc_setattr, |
---|
| 3543 | + .permission = proc_tid_comm_permission, |
---|
3514 | 3544 | }; |
---|
3515 | 3545 | |
---|
3516 | 3546 | /* |
---|
.. | .. |
---|
3643 | 3673 | struct task_struct *task, const void *ptr) |
---|
3644 | 3674 | { |
---|
3645 | 3675 | struct inode *inode; |
---|
3646 | | - inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO); |
---|
| 3676 | + inode = proc_pid_make_base_inode(dentry->d_sb, task, |
---|
| 3677 | + S_IFDIR | S_IRUGO | S_IXUGO); |
---|
3647 | 3678 | if (!inode) |
---|
3648 | 3679 | return ERR_PTR(-ENOENT); |
---|
3649 | 3680 | |
---|