From patchwork Fri Aug 28 18:56:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Paris X-Patchwork-Id: 32414 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 66E24B7087 for ; Sat, 29 Aug 2009 05:00:18 +1000 (EST) Received: by ozlabs.org (Postfix) id 5A85ADDD0B; Sat, 29 Aug 2009 05:00:18 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id C4AEBDDD01 for ; Sat, 29 Aug 2009 05:00:17 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752480AbZH1S4U (ORCPT ); Fri, 28 Aug 2009 14:56:20 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752397AbZH1S4S (ORCPT ); Fri, 28 Aug 2009 14:56:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57123 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752388AbZH1S4Q (ORCPT ); Fri, 28 Aug 2009 14:56:16 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7SIuDSc027677; Fri, 28 Aug 2009 14:56:14 -0400 Received: from paris.rdu.redhat.com (paris.rdu.redhat.com [10.11.231.241]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7SIuCHU015500; Fri, 28 Aug 2009 14:56:12 -0400 From: Eric Paris Subject: [PATCH 5/9] fanotify:drop notification if they exist in the outgoing queue To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org Cc: davem@davemloft.net, viro@zeniv.linux.org.uk, alan@linux.intel.com, hch@infradead.org Date: Fri, 28 Aug 2009 14:56:12 -0400 Message-ID: <20090828185611.8014.4931.stgit@paris.rdu.redhat.com> In-Reply-To: <20090828185542.8014.22791.stgit@paris.rdu.redhat.com> References: <20090828185542.8014.22791.stgit@paris.rdu.redhat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org fanotify listeners get an open file descriptor to the object in question so the ordering of operations is not as important as in other notification systems. inotify will drop events if the last event in the event FIFO is the same as the current event. This patch will drop fanotify events if they are the same as another event anywhere in the event FIFO. Signed-off-by: Eric Paris --- fs/notify/fanotify/fanotify.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 59bc883..caf34bb 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -8,6 +8,40 @@ #include "fanotify.h" +static bool try_merge(struct fsnotify_event *old, struct fsnotify_event *new) +{ + if ((old->mask == new->mask) && + (old->to_tell == new->to_tell) && + (old->data_type == new->data_type)) { + switch (old->data_type) { + case (FSNOTIFY_EVENT_PATH): + if ((old->path.mnt == new->path.mnt) && + (old->path.dentry == new->path.dentry)) + return true; + case (FSNOTIFY_EVENT_NONE): + return true; + default: + BUG(); + }; + } + return false; +} + +static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) +{ + struct fsnotify_event_holder *holder; + struct fsnotify_event *test_event; + + /* and the list better be locked by something too! */ + + list_for_each_entry_reverse(holder, list, event_list) { + test_event = holder->event; + if (try_merge(test_event, event)) + return -EEXIST; + } + + return 0; +} static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event) { int ret; @@ -20,8 +54,10 @@ static int fanotify_handle_event(struct fsnotify_group *group, struct fsnotify_e BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD); BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW); - ret = fsnotify_add_notify_event(group, event, NULL, NULL); - + ret = fsnotify_add_notify_event(group, event, NULL, fanotify_merge); + /* -EEXIST means this event was merged with another, not that it was an error */ + if (ret == -EEXIST) + ret = 0; return ret; }