From patchwork Thu Sep 8 14:25:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9321497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F0356077F for ; Thu, 8 Sep 2016 14:26:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FF40298A4 for ; Thu, 8 Sep 2016 14:26:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44C75298AA; Thu, 8 Sep 2016 14:26:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA24F298A4 for ; Thu, 8 Sep 2016 14:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758321AbcIHO0A (ORCPT ); Thu, 8 Sep 2016 10:26:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:38578 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758272AbcIHOZ7 (ORCPT ); Thu, 8 Sep 2016 10:25:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D8B43ABE8; Thu, 8 Sep 2016 14:25:57 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6A8351E0997; Thu, 8 Sep 2016 16:25:57 +0200 (CEST) From: Jan Kara To: linux-fsdevel@vger.kernel.org Cc: Miklos Szeredi , Al Viro , Lino Sanfilippo , Eric Paris , Jan Kara Subject: [PATCH 2/3] fsnotify: Add a way to stop queueing events on group shutdown Date: Thu, 8 Sep 2016 16:25:44 +0200 Message-Id: <1473344745-20634-3-git-send-email-jack@suse.cz> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1473344745-20634-1-git-send-email-jack@suse.cz> References: <1473344745-20634-1-git-send-email-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement a function that can be called when a group is being shutdown to stop queueing new events to the group. Fanotify will use this. Signed-off-by: Jan Kara Reviewed-by: Miklos Szeredi --- fs/notify/group.c | 19 +++++++++++++++++++ fs/notify/notification.c | 5 +++++ include/linux/fsnotify_backend.h | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/fs/notify/group.c b/fs/notify/group.c index 3e2dd85be5dd..b47f7cfdcaa4 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -40,6 +40,17 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group) } /* + * Stop queueing new events for this group. Once this function returns + * fsnotify_add_event() will not add any new events to the group's queue. + */ +void fsnotify_group_stop_queueing(struct fsnotify_group *group) +{ + mutex_lock(&group->notification_mutex); + group->shutdown = true; + mutex_unlock(&group->notification_mutex); +} + +/* * Trying to get rid of a group. Remove all marks, flush all events and release * the group reference. * Note that another thread calling fsnotify_clear_marks_by_group() may still @@ -47,6 +58,14 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group) */ void fsnotify_destroy_group(struct fsnotify_group *group) { + /* + * Stop queueing new events. The code below is careful enough to not + * require this but fanotify needs to stop queuing events even before + * fsnotify_destroy_group() is called and this makes the other callers + * of fsnotify_destroy_group() to see the same behavior. + */ + fsnotify_group_stop_queueing(group); + /* clear all inode marks for this group, attach them to destroy_list */ fsnotify_detach_group_marks(group); diff --git a/fs/notify/notification.c b/fs/notify/notification.c index 12bfd6790fc4..af0497cac06c 100644 --- a/fs/notify/notification.c +++ b/fs/notify/notification.c @@ -96,6 +96,11 @@ enum fsn_add_event_ret fsnotify_add_event( mutex_lock(&group->notification_mutex); + if (group->shutdown) { + mutex_unlock(&group->notification_mutex); + return AE_SHUTDOWN; + } + if (group->q_len >= group->max_events) { ret = AE_OVERFLOW; /* Queue overflow event only if it isn't already queued */ diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index b948a52ce65f..bcba826a99fc 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -148,6 +148,7 @@ struct fsnotify_group { #define FS_PRIO_1 1 /* fanotify content based access control */ #define FS_PRIO_2 2 /* fanotify pre-content access */ unsigned int priority; + bool shutdown; /* group is being shut down, don't queue more events */ /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ struct mutex mark_mutex; /* protect marks_list */ @@ -292,6 +293,8 @@ extern struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *op extern void fsnotify_get_group(struct fsnotify_group *group); /* drop reference on a group from fsnotify_alloc_group */ extern void fsnotify_put_group(struct fsnotify_group *group); +/* group destruction begins, stop queuing new events */ +extern void fsnotify_group_stop_queueing(struct fsnotify_group *group); /* destroy group */ extern void fsnotify_destroy_group(struct fsnotify_group *group); /* fasync handler function */ @@ -304,6 +307,7 @@ enum fsn_add_event_ret { AE_INSERTED, /* Event was added in the queue */ AE_MERGED, /* Event was merged with another event, passed event unused */ AE_OVERFLOW, /* Queue overflow, passed event unused */ + AE_SHUTDOWN, /* Group is being released, passed event unused */ }; /* attach the event to the group notification queue */ extern enum fsn_add_event_ret fsnotify_add_event(