Skip to contentSkip to conversation

Using inotify on /proc/partitoins

BUG majianpeng 2 participants 2 messages Jun 14, 2013

lore
Share & tools
lore

majianpeng

author
#0 lore raw

Hi all,
I wanted to monitor /proc/partitions using inotify.Although now i know it can't catch the event of write.
But for read,it can't catch. The code is:
int main()

{
	int fd = inotify_init();
	int wd;
	char buff[4096];
	int ret;
	if (fd < 0)
		perror("inotify_init error\n");

	wd = inotify_add_watch(fd, "/proc/partitions", IN_ACCESS);
	if (wd < 0)
		perror("inotify_add_watch error\n");

	
	ret = read(fd, buff, 4096);
	if (ret < 0)
		perror("read error\n");
	else
		printf("buff %s\n", buff);
	return 0;
}

But when i call 'cat /proc/partitions',the program can't return.
So i added some message in kernel in order to find the reason.
In procfs for some files, the inode used this method to alloc. proc_lookup-->proc_lookup_de--->proc_get_inode-->new_inode_pseudo
In new_inode_pseudo, it will alloc new inode so every open-operation procfs will alloc new inode. So inotify can't work.

I think it should add a flag which indicate file can't support inotify.Although there are a few files in procfs.

Thanks!
Jianpeng �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�

#1 lore raw
Quoted 2 lines · majianpeng

Hi all,
I wanted to monitor /proc/partitions using inotify.

That, indeed, is a bug. Easily fixed - don't do that.

Quoted 6 lines

But when i call 'cat /proc/partitions',the program can't return.
So i added some message in kernel in order to find the reason.
In procfs for some files, the inode used this method to alloc. proc_lookup-->proc_lookup_de--->proc_get_inode-->new_inode_pseudo
In new_inode_pseudo, it will alloc new inode so every open-operation procfs will alloc new inode. So inotify can't work.

Of course, it can't work. Inotify if a kludge that kinda-sorta works for local disk-backed filesystems, if you do not mind a pile of races. For anything else it's completely worthless.