From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: John McCutchan
<john-jueV0HHMeujJJrXXpGQQMAC/G2K4zDHf@public.gmane.org>,
Robert Love <rlove-L7G0xEPcOZbYtjvyW6yDsg@public.gmane.org>,
Eric Paris <eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Lennart Poettering
<lennart-mdGvqq1h2p+GdvJs77BJ7Q@public.gmane.org>,
radu.voicilas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
daniel-dYEgDbNUoShWk0Htik3J/w@public.gmane.org,
Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Vegard Nossum
<vegard.nossum-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>,
"linux-fsdevel@vger.kernel.org"
<linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
linux-man <linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
gamin-list-rDKQcyrBJuzYtjvyW6yDsg@public.gmane.org,
lkml <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
inotify-tools-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: Things I wish I'd known about Inotify
Date: Thu, 03 Apr 2014 08:38:40 -0700 [thread overview]
Message-ID: <871txeifsv.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <CAKgNAkjymzawYMKZGedK=fai55cwo4p=yeYe6GT8MdxWON__zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> (Michael Kerrisk's message of "Thu, 3 Apr 2014 08:34:44 +0200")
"Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> (To: == [the set of people I believe know a lot about inotify])
>
> Hello all,
>
> Lately, I've been studying the inotify API fairly thoroughly and
> realized that there's a very big gap between knowing what the system
> calls do versus using them to reliably and efficiently monitor the
> state of a set of filesystem objects.
>
> With that in mind, I've drafted some substantial additions to the
> inotify(7) man page. I would be very happy if folk on the "To:" list
> could comment on the text below, since I believe you all have a lot of
> practical experience with Inotify. (Of course, I also welcome comments
> from anyone else.) In particular, I would like comments on the
> accuracy of the various technical points (especially those relating to
> matching up related IN_MOVED_FROM and IN_MOVED_TO events), as well as
> pointers on any other pitfalls that the programmers should be wary of
> that should be added to the page.
Other pitfalls.
Inotify only report events that a user space program triggers through
the filesystem API. Which means inotify is limited for remote
filesystems, and filesystems like proc and sys have no monitorable
events.
Eric
> Thanks,
>
> Michael
>
> Limitations and caveats
> The inotify API provides no information about the user or process
> that triggered the inotify event. In particular, there is no
> easy way for a process that is monitoring events via inotify to
> distinguish events that it triggers itself from those that are
> triggered by other processes.
>
> The inotify API identifies affected files by filename. However,
> by the time an application processes an inotify event, the file‐
> name may already have been deleted or renamed.
>
> The inotify API identifies events via watch descriptors. It is
> the application's responsibility to cache a mapping (if one is
> needed) between watch descriptors and pathnames. Be aware that
> directory renamings may affect multiple cached pathnames.
>
> Inotify monitoring of directories is not recursive: to monitor
> subdirectories under a directory, additional watches must be cre‐
> ated. This can take a significant amount time for large direc‐
> tory trees.
>
> If monitoring an entire directory subtree, and a new subdirectory
> is created in that tree or an existing directory is renamed into
> that tree, be aware that by the time you create a watch for the
> new subdirectory, new files (and subdirectories) may already
> exist inside the subdirectory. Therefore, you may want to scan
> the contents of the subdirectory immediately after adding the
> watch (and, if desired, recursively add watches for any subdirec‐
> tories that it contains).
>
> Note that the event queue can overflow. In this case, events are
> lost. Robust applications should handle the possibility of lost
> events gracefully. For example, it may be necessary to rebuild
> part or all of the application cache. (One simple, but possibly
> expensive, approach is to close the inotify file descriptor,
> empty the cache, create a new inotify file descriptor, and then
> re-create watches and cache entries for the objects to be moni‐
> tored.)
>
> Dealing with rename() events
> The IN_MOVED_FROM and IN_MOVED_TO events that are generated by
> rename(2) are usually available as consecutive events when read‐
> ing from the inotify file descriptor. However, this is not guar‐
> anteed. If multiple processes are triggering events for moni‐
> tored objects, then (on rare occasions) an arbitrary number of
> other events may appear between the IN_MOVED_FROM and IN_MOVED_TO
> events.
>
> Matching up the IN_MOVED_FROM and IN_MOVED_TO event pair gener‐
> ated by rename(2) is thus inherently racy. (Don't forget that if
> an object is renamed outside of a monitored directory, there may
> not even be an IN_MOVED_TO event.) Heuristic approaches (e.g.,
> assume the events are always consecutive) can be used to ensure a
> match in most cases, but will inevitably miss some cases, causing
> the application to perceive the IN_MOVED_FROM and IN_MOVED_TO
> events as being unrelated. If watch descriptors are destroyed
> and re-created as a result, then those watch descriptors will be
> inconsistent with the watch descriptors in any pending events.
> (Re-creating the inotify file descriptor and rebuilding the cache
> may be useful to deal with this scenario.)
>
> Applications should also allow for the possibility that the
> IN_MOVED_FROM event was the last event that could fit in the buf‐
> fer returned by the current call to read(2), and the accompanying
> IN_MOVED_TO event might be fetched only on the next read(2).
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-04-03 15:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 6:34 Things I wish I'd known about Inotify Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkjymzawYMKZGedK=fai55cwo4p=yeYe6GT8MdxWON__zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-03 15:38 ` Eric W. Biederman [this message]
2014-04-04 7:59 ` Michael Kerrisk (man-pages)
2014-04-04 20:24 ` Stef Bon
2014-04-03 20:52 ` Jan Kara
2014-04-04 7:35 ` Michael Kerrisk (man-pages)
[not found] ` <533E60D6.2000704-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-04 12:43 ` Jan Kara
2014-04-06 9:00 ` Michael Kerrisk (man-pages)
[not found] ` <534117AD.1030708-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-07 9:31 ` Jan Kara
[not found] ` <20140407093152.GC14927-+0h/O2h83AeN3ZZ/Hiejyg@public.gmane.org>
2014-04-12 5:44 ` Michael Kerrisk (man-pages)
2014-07-12 19:06 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkj=j2Auym+Euis0qYot3nYoASkeaf4kFPWvL-M-FCXEvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-14 11:28 ` Jan Kara
2014-07-15 4:15 ` Michael Kerrisk (man-pages)
2014-04-04 13:00 ` David Herrmann
[not found] ` <CANq1E4RzNA_ajEwf1rRbTa8xOP392_YfD0mShK6QV=FexoOpUA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-04 13:08 ` David Herrmann
2014-04-04 14:50 ` Eric Paris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871txeifsv.fsf@x220.int.ebiederm.org \
--to=ebiederm-as9lmozglivwk0htik3j/w@public.gmane.org \
--cc=daniel-dYEgDbNUoShWk0Htik3J/w@public.gmane.org \
--cc=eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=gamin-list-rDKQcyrBJuzYtjvyW6yDsg@public.gmane.org \
--cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=inotify-tools-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=john-jueV0HHMeujJJrXXpGQQMAC/G2K4zDHf@public.gmane.org \
--cc=lennart-mdGvqq1h2p+GdvJs77BJ7Q@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=radu.voicilas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=rlove-L7G0xEPcOZbYtjvyW6yDsg@public.gmane.org \
--cc=vegard.nossum-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).