【问题标题】:Why can the posix thread id be NULL in Linux kernel function filp_close?为什么 Linux 内核函数 filp_close 中的 posix 线程 id 可以为 NULL?
【发布时间】:2015-12-03 05:41:05
【问题描述】:

以下摘自linux内核:

/*
 * "id" is the POSIX thread ID. We use the
 * files pointer for this..
 */
int filp_close(struct file *filp, fl_owner_t id)

文档说id 是posix 线程ID,它应该是current->files

但是,我在 Linux 内核中发现了很多用法,例如acct_on,把它当成filp_close(filp, NULL)

我的问题是:

为什么调用filp_close时可以接受NULL?

id 参数的意图是什么?

【问题讨论】:

    标签: linux file linux-kernel posix rationale


    【解决方案1】:

    根据这个discussionfl_owner_t 的正式描述将是

    A generic "file lock owner" value. This is set differently for different 
    types of locks. 
    
    The POSIX file lock owner is determined by the "struct files_struct" in the 
    thread group. 
    
    Flock (BSD) locks, OFD locks and leases set the fl_owner to the 
    file description pointer. 
    

    但实际上这是不透明的指针

    legacy typedef, should eventually go away
    

    指的是进程文件描述符表(struct files_struct)。

    对于filp_close函数,只有fs/file.c源使用非NULL的id参数。所有其他用户手动创建filp(使用filp_openfile_open_name)并将id 传递为NULL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      相关资源
      最近更新 更多