From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zx9PL-0003tJ-PG for qemu-devel@nongnu.org; Fri, 13 Nov 2015 03:08:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zx9PG-0002FE-M7 for qemu-devel@nongnu.org; Fri, 13 Nov 2015 03:08:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zx9PG-0002F3-GH for qemu-devel@nongnu.org; Fri, 13 Nov 2015 03:08:26 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 5B53037FF50 for ; Fri, 13 Nov 2015 08:08:25 +0000 (UTC) Message-ID: <1447402103.1400.89.camel@redhat.com> From: Gerd Hoffmann Date: Fri, 13 Nov 2015 09:08:23 +0100 In-Reply-To: References: <1446595225-23608-1-git-send-email-bsd@redhat.com> <1446595225-23608-3-git-send-email-bsd@redhat.com> <1446713343.30393.16.camel@redhat.com> <1447316181.1400.21.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] usb-mtp: Add support for inotify based file monitoring List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bandan Das Cc: qemu-devel@nongnu.org Hi, > Maybe I am missing something but what if the watch on dir was > added by qemu _after_ the file (say file1) was copied to it. > Then, the kernel would generate events for file2, file3 and so on but > never a CREATE event for file1. Isn't that a possibility ? Yes. > So, what I mean > by that comment is that add a watchpoint soon enough but it could be > possible that by the time the watch is added, a few files might have already > been copied and will not generate events. The readdir (in usb_mtp_object_readdir) will find them then. While looking at the code: I think there is no need to add the watch right away. We only read the directory when the guest actually requests it. Watching the directories we actually have scanned due to the guest requesting it should be enough. So I think adding the inotify watch in usb_mtp_object_readdir should work just fine. And the watch should be added before readdir to make sure we don't miss anything. File system events then can happen at three points in time: (a) before we add the watch, (b) after we add the watch, and before readdir, and (c) after readdir. (a) we will see these files in the readdir call. (b) we will see these files in the readdir call *and* receive inotify events for them. (c) we will only get events for them. The (b) events look bogous at first glance (create events for files you already have in the list, but also delete events for files you don't have in your list). cheers, Gerd