linux inotify 触发点探秘

起因

之前写过一篇通过inotify来实现高性能的文件队列的文章,对inotify触发的点有些疑问,到底是底层文件发生变化后才trigger event还是在write complete后才触发的event。有必要搞清楚这个问题。

分析

查看vfs write相关源码https://github.com/torvalds/linux/blob/master/fs/read_write.c

static ssize_t __vfs_write(struct file *file, const char __user *p,
			   size_t count, loff_t *pos)
{
	if (file->f_op->write)
		return file->f_op->write(file, p, count, pos);
	else if (file->f_op->write_iter)
		return new_sync_write(file, p, count, pos);
	else
		return -EINVAL;
}

ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos)
{
	mm_segment_t old_fs;
	const char __user *p;
	ssize_t ret;

	if (!(file->f_mode & FMODE_CAN_WRITE))
		return -EINVAL;

	old_fs = get_fs();
	set_fs(KERNEL_DS);
	p = (__force const char __user *)buf;
	if (count > MAX_RW_COUNT)
		count = 

你可能感兴趣的:(c)