你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux内核中的文件描述符(三)--fd的回收

[日期:2013-01-11] 来源:Linux社区  作者:ce123 [字体:大 中 小]

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);
}

linux
相关资讯       Linux内核学习  Linux内核分析 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款