smbd: Sort notify events by timestamp
authorVolker Lendecke <vl@samba.org>
Fri, 4 Apr 2014 19:12:06 +0000 (21:12 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 23 Apr 2014 20:33:08 +0000 (22:33 +0200)
This will fix the raw.notify test with the new messaging system. With the new
messaging system messages come in via yet another fd that has to line up in
poll next to the incoming client TCP socket. With the signal-based messaging
messages were always handled before client requests. The new scheme means that
notify messages might be deferred a bit (something which can happen in a
cluster already now), which then means that notify_marshall_changes() will
coalesce entries, which in turn makes raw.notify unhappy.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/notify.c

index b8085dd6c429ce93e4d49968b854a224bfedd746..dd4dc1ad4b895a91d458dab7472b40780380bffb 100644 (file)
@@ -170,6 +170,14 @@ static bool notify_marshall_changes(int num_changes,
        return True;
 }
 
+static int compare_notify_change_events(const void *p1, const void *p2)
+{
+       const struct notify_change_event *e1 = p1;
+       const struct notify_change_event *e2 = p2;
+
+       return timespec_compare(&e1->when, &e2->when);
+}
+
 /****************************************************************************
  Setup the common parts of the return packet and send it.
 *****************************************************************************/
@@ -194,6 +202,14 @@ void change_notify_reply(struct smb_request *req,
                return;
        }
 
+       /*
+        * Sort the notifies by timestamp when the event happened to avoid
+        * coalescing and thus dropping events in notify_marshall_changes.
+        */
+
+       qsort(notify_buf->changes, notify_buf->num_changes,
+             sizeof(*(notify_buf->changes)), compare_notify_change_events);
+
        if (!notify_marshall_changes(notify_buf->num_changes, max_param,
                                        notify_buf->changes, &blob)) {
                /*