3.关闭文件filp_close
int filp_close(struct file *filp, fl_owner_t id)
{
int retval = 0;
if (!file_count(filp)) {
printk(KERN_ERR "VFS: Close: file count is 0\n");
return 0;
}
if (filp->f_op && filp->f_op->flush)
retval = filp->f_op->flush(filp);
dnotify_flush(filp, id);
locks_remove_posix(filp, id);
fput(filp);
return retval;
}
filp_close函数调用fput,在fput中调用release函数。
//fs/file_table.c
void fastcall fput(struct file *file)
{
if (rcuref_dec_and_test(&file->f_count))
__fput(file);
}
void fastcall __fput(struct file *file)
{
struct dentry *dentry = file->f_dentry;
struct vfsmount *mnt = file->f_vfsmnt;
struct inode *inode = dentry->d_inode;
might_sleep();
fsnotify_close(file);
/*
* The function eventpoll_release() should be the first called
* in the file cleanup chain.
*/
eventpoll_release(file);
locks_remove_flock(file);
if (file->f_op && file->f_op->release)
file->f_op->release(inode, file);//在这里调用release函数。在socket中即socket_close函数
security_file_free(file);
if (unlikely(inode->i_cdev != NULL))
cdev_put(inode->i_cdev);
fops_put(file->f_op);
if (file->f_mode & FMODE_WRITE)
put_write_access(inode);
file_kill(file);
file->f_dentry = NULL;
file->f_vfsmnt = NULL;
file_free(file);
dput(dentry);
mntput(mnt);
}
