This splits up fsnotify_remove_first_event() and fsnotify_peek_first_event()
into a helper function with a wrapper, and introduces two new versions that
takes a list instead of the group as argument.

Signed-off-by: Jes Sorensen <[email protected]>
Reviewed-by: Josef Bacik <[email protected]>
---
 fs/notify/notification.c         | 38 +++++++++++++++++++++++++++++++-------
 include/linux/fsnotify_backend.h |  4 ++++
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index 66f85c6..7b38cf8 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -144,26 +144,43 @@ int fsnotify_add_event(struct fsnotify_group *group,
  * Remove and return the first event from the notification list.  It is the
  * responsibility of the caller to destroy the obtained event
  */
-struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group 
*group)
+struct fsnotify_event *
+__fsnotify_remove_first_event(struct list_head *notification_list)
 {
        struct fsnotify_event *event;
 
-       assert_spin_locked(&group->notification_lock);
-
-       pr_debug("%s: group=%p\n", __func__, group);
-
-       event = list_first_entry(&group->notification_list,
+       event = list_first_entry(notification_list,
                                 struct fsnotify_event, list);
        /*
         * We need to init list head for the case of overflow event so that
         * check in fsnotify_add_event() works
         */
        list_del_init(&event->list);
-       group->q_len--;
 
        return event;
 }
 
+struct fsnotify_event *fsnotify_remove_first_event(struct fsnotify_group 
*group)
+{
+       struct list_head *notification_list = &group->notification_list;
+
+       assert_spin_locked(&group->notification_lock);
+
+       pr_debug("%s: group=%p\n", __func__, group);
+
+       group->q_len--;
+       return __fsnotify_remove_first_event(notification_list);
+}
+
+/*
+ * Note this version doesn't update the queue depth counter.
+ */
+struct fsnotify_event *
+fsnotify_list_remove_first_event(struct list_head *notification_list)
+{
+       return __fsnotify_remove_first_event(notification_list);
+}
+
 /*
  * This will not remove the event, that must be done with
  * fsnotify_remove_first_event()
@@ -176,6 +193,13 @@ struct fsnotify_event *fsnotify_peek_first_event(struct 
fsnotify_group *group)
                                struct fsnotify_event, list);
 }
 
+struct fsnotify_event *
+fsnotify_list_peek_first_event(struct list_head *notification_list)
+{
+       return list_first_entry(notification_list,
+                               struct fsnotify_event, list);
+}
+
 /*
  * Called when a group is being torn down to clean up any outstanding
  * event notifications.
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index e0686ed..80d4c3b 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -313,8 +313,12 @@ extern int fsnotify_add_event(struct fsnotify_group *group,
 extern bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group);
 /* return, but do not dequeue the first event on the notification queue */
 extern struct fsnotify_event *fsnotify_peek_first_event(struct fsnotify_group 
*group);
+/* return, but do not dequeue the first event on the notification list */
+extern struct fsnotify_event *fsnotify_list_peek_first_event(struct list_head 
*notification_list);
 /* return AND dequeue the first event on the notification queue */
 extern struct fsnotify_event *fsnotify_remove_first_event(struct 
fsnotify_group *group);
+/* return AND dequeue the first event on the notification list */
+extern struct fsnotify_event *fsnotify_list_remove_first_event(struct 
list_head *notification_list);
 
 /* functions used to manipulate the marks attached to inodes */
 
-- 
2.9.3

Reply via email to