From patchwork Fri Aug 28 18:56:19 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Paris X-Patchwork-Id: 32415 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 22C50B7087 for ; Sat, 29 Aug 2009 05:00:19 +1000 (EST) Received: by ozlabs.org (Postfix) id 1721ADDD0B; Sat, 29 Aug 2009 05:00:19 +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 90C00DDD01 for ; Sat, 29 Aug 2009 05:00:18 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752555AbZH1S4d (ORCPT ); Fri, 28 Aug 2009 14:56:33 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752510AbZH1S4b (ORCPT ); Fri, 28 Aug 2009 14:56:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27779 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752532AbZH1S42 (ORCPT ); Fri, 28 Aug 2009 14:56:28 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7SIuLgM026704; Fri, 28 Aug 2009 14:56:21 -0400 Received: from paris.rdu.redhat.com (paris.rdu.redhat.com [10.11.231.241]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7SIuJF6032046; Fri, 28 Aug 2009 14:56:20 -0400 From: Eric Paris Subject: [PATCH 6/9] fanotify: merge notification events with different masks 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:19 -0400 Message-ID: <20090828185618.8014.55255.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.18 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Instead of just merging fanotify events if they are exactly the same, merge notification events with different masks. To do this we have to clone the old event, update the mask in the new event with the new merged mask, and put the new event in place of the old event. Signed-off-by: Eric Paris --- fs/notify/fanotify/fanotify.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 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 caf34bb..e8e56cb 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -10,8 +10,7 @@ static bool try_merge(struct fsnotify_event *old, struct fsnotify_event *new) { - if ((old->mask == new->mask) && - (old->to_tell == new->to_tell) && + if ((old->to_tell == new->to_tell) && (old->data_type == new->data_type)) { switch (old->data_type) { case (FSNOTIFY_EVENT_PATH): @@ -29,15 +28,28 @@ static bool try_merge(struct fsnotify_event *old, struct fsnotify_event *new) static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) { - struct fsnotify_event_holder *holder; + struct fsnotify_event_holder *test_holder, *prev; struct fsnotify_event *test_event; + struct fsnotify_event *new_event; + int ret; /* 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)) + list_for_each_entry_safe_reverse(test_holder, prev, list, event_list) { + test_event = test_holder->event; + if (try_merge(test_event, event)) { + if (test_event->mask == event->mask) + return -EEXIST; + new_event = fsnotify_clone_event(test_event); + if (!new_event) + return 0; + new_event->mask = (test_event->mask | event->mask); + ret = fsnotify_replace_event(test_holder, new_event); + fsnotify_put_event(new_event); /* matches the ref from clone */ + if (ret) + return ret; return -EEXIST; + } } return 0;