From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Subject: Re: inotify/sysfs Date: Fri, 28 Mar 2014 23:25:49 -0700 Message-ID: <20140329062549.GA27723@kroah.com> References: <53342CA0.905@sardemff7.net> <20140328170713.GA11990@quack.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jan Kara To: Quentin Glidic , linux-fsdevel@vger.kernel.org Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:59410 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbaC2QqI (ORCPT ); Sat, 29 Mar 2014 12:46:08 -0400 Content-Disposition: inline In-Reply-To: <20140328170713.GA11990@quack.suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Mar 28, 2014 at 06:07:13PM +0100, Jan Kara wrote: > Hello, > > On Thu 27-03-14 14:50:24, Quentin Glidic wrote: > > In GIO (GLib), the GFileMonitor[1] mechanism is using inotify for > > local files. To detect file creation and some other weird cases, > > they monitor the directory of the file and not the file directly > > (see get_basename/get_dirname[2] usage). > > > > With sysfs, it does not work as expected for some reason. > Well, I'm rather surprised inotify works with sysfs at all ;) Why do you > need to watch sysfs? Udev is the tool with which you should generally look > for e.g. new devices... Anyway, if you'd like to add fsnotify() support > into sysfs, sysfs maintainer (Greg - added to CC) is the one to ask. You forgot to cc: me :) No, inotify doesn't work on sysfs, or if it does, that's by "accident", and any data you are getting for this is probably totally wrong. This is because the system would have to be constantly "opening" the files to check for a value change in the kernel that represents the file information. That would be hell on memory and overhead and just doesn't make any sense at all. For specific sysfs files that are ment to tell userspace that their values changed, you can poll() on them, as they are set up to do this properly. If there are some specific sysfs files that you want to watch in this manner, that don't support poll(), please let us know. Also, if you are digging through sysfs files in the system, I'd recommend using libudev, as that provides a much easier interface to getting the data you need about the device you want. thanks, greg k-h