From: Bandan Das <bsd@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/4] usb-mtp: Add support for inotify based file monitoring
Date: Fri, 13 Nov 2015 12:16:59 -0500 [thread overview]
Message-ID: <jpgr3jt95v8.fsf@linux.bootlegged.copy> (raw)
In-Reply-To: <1447418075.1400.110.camel@redhat.com> (Gerd Hoffmann's message of "Fri, 13 Nov 2015 13:34:35 +0100")
Gerd Hoffmann <kraxel@redhat.com> writes:
> Hi,
>
>> + switch (mask) {
>> + case IN_CREATE:
>> + if (event->mask & IN_ISDIR) {
>> + /*
>> + * Add the watchpoint first so we
>> + * don't miss events in this subdir
>> + */
>> + name = g_strndup(event->name, event->len);
>> + path = g_strdup_printf("%s/%s", parent->path, name);
>> +
>> + watchfd = usb_mtp_add_watch(s->inotifyfd, path);
>> + g_free(path);
>> + g_free(name);
>> +
>> + if (watchfd == -1) {
>> + continue;
>> + }
>> + }
>
> So, to follow up my mail from today in the morning:
>
> I think this is not needed here ...
>
>> usb_mtp_object_readdir(s, o);
>> + if (usb_mtp_inotify_mon(s, o)) {
>> + fprintf(stderr, "usb-mtp: adding watch for %s failed\n", o->path);
>> + }
>
> ... but here we have to add the watch first, then read the directory.
> When reading the directory first we'll miss new files which are added
> after readdir() but before add_watch().
Yep, this makes sense. So:
1. No need to add watch as soon as possible. As long as the guest knows there
is a directory(which it would because of the create event), it can request contents
at any time.
2. When it does, the first thing to do is add a watchpoint. Then, readdir does its thing
getting the dir contents and the watchpoint which has already been added will track new
changes.
3. We don't have to worry about content changes before the guest has requested
the folder contents.
Thanks for the review!
> cheers,
> Gerd
next prev parent reply other threads:[~2015-11-13 17:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 22:58 [Qemu-devel] [PATCH v2 0/4] usb-mtp events support Bandan Das
2015-11-10 22:58 ` [Qemu-devel] [PATCH v2 1/4] usb-mtp: use a list for keeping track of children Bandan Das
2015-11-10 22:58 ` [Qemu-devel] [PATCH v2 2/4] usb-mtp: free objects on a mtp reset Bandan Das
2015-11-10 22:58 ` [Qemu-devel] [PATCH v2 3/4] usb-mtp: Add support for inotify based file monitoring Bandan Das
2015-11-13 12:34 ` Gerd Hoffmann
2015-11-13 17:16 ` Bandan Das [this message]
2015-11-10 22:58 ` [Qemu-devel] [PATCH v2 4/4] usb-mtp: add support for basic mtp events Bandan Das
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=jpgr3jt95v8.fsf@linux.bootlegged.copy \
--to=bsd@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.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).