From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com ([74.125.82.65]:35012 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751165AbeDENRQ (ORCPT ); Thu, 5 Apr 2018 09:17:16 -0400 Received: by mail-wm0-f65.google.com with SMTP id r82so7135030wme.0 for ; Thu, 05 Apr 2018 06:17:15 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Miklos Szeredi , Marko Rauhamaa , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 07/20] fsnotify: introduce marks iteration helpers Date: Thu, 5 Apr 2018 16:18:08 +0300 Message-Id: <1522934301-6520-8-git-send-email-amir73il@gmail.com> In-Reply-To: <1522934301-6520-1-git-send-email-amir73il@gmail.com> References: <1522934301-6520-1-git-send-email-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Introduce helpers fsnotify_iter_first() and fsnotify_iter_next() to abstract the inode / vfsmount marks merged list iteration. This is a preparation patch before generalizing mark list iteration to more mark object types (i.e. super block marks). Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 68 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index cb0afa664057..665f681dd913 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -261,6 +261,48 @@ static struct fsnotify_mark *fsnotify_next_mark(struct fsnotify_mark *mark) } /* + * iter_info is a multi head priority queue of marks. + * fsnotify_iter_first() picks a subset of marks from queue heads, all with the + * same priority and clears the type_mask for other marks. + * Returns the type_mask of the chosen subset. + */ +static unsigned int fsnotify_iter_first(struct fsnotify_iter_info *iter_info) +{ + struct fsnotify_mark *inode_mark = iter_info->inode_mark; + struct fsnotify_mark *vfsmount_mark = iter_info->vfsmount_mark; + + if (inode_mark && vfsmount_mark) { + int cmp = fsnotify_compare_groups(inode_mark->group, + vfsmount_mark->group); + if (cmp > 0) + iter_info->type_mask &= ~FSNOTIFY_OBJ_TYPE_INODE_FL; + else if (cmp < 0) + iter_info->type_mask &= ~FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL; + } + + return iter_info->type_mask; +} + +/* + * Pop from iter_info multi head queue, the marks that were iterated in the + * current iteration step and set type_mask for all non NULL marks. + */ +static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) +{ + if (iter_info->type_mask & FSNOTIFY_OBJ_TYPE_INODE_FL) + fsnotify_iter_set_inode_mark(iter_info, + fsnotify_next_mark(iter_info->inode_mark)); + else if (iter_info->inode_mark) + iter_info->type_mask |= FSNOTIFY_OBJ_TYPE_INODE_FL; + + if (iter_info->type_mask & FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL) + fsnotify_iter_set_vfsmount_mark(iter_info, + fsnotify_next_mark(iter_info->vfsmount_mark)); + else if (iter_info->vfsmount_mark) + iter_info->type_mask |= FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL; +} + +/* * This is the main call to fsnotify. The VFS calls into hook specific functions * in linux/fsnotify.h. Those functions then in turn call here. Here will call * out to all of the registered fsnotify_group. Those groups can then use the @@ -321,36 +363,14 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, * ignore masks are properly reflected for mount mark notifications. * That's why this traversal is so complicated... */ - while (iter_info.type_mask) { - struct fsnotify_mark *inode_mark = iter_info.inode_mark; - struct fsnotify_mark *vfsmount_mark = iter_info.vfsmount_mark; - - if (inode_mark && vfsmount_mark) { - int cmp = fsnotify_compare_groups(inode_mark->group, - vfsmount_mark->group); - if (cmp > 0) - iter_info.type_mask &= ~FSNOTIFY_OBJ_TYPE_INODE_FL; - else if (cmp < 0) - iter_info.type_mask &= ~FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL; - } - + while (fsnotify_iter_first(&iter_info)) { ret = send_to_group(to_tell, mask, data, data_is, cookie, file_name, &iter_info); if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) goto out; - if (iter_info.type_mask & FSNOTIFY_OBJ_TYPE_INODE_FL) - fsnotify_iter_set_inode_mark(&iter_info, - fsnotify_next_mark(iter_info.inode_mark)); - else if (iter_info.inode_mark) - iter_info.type_mask |= FSNOTIFY_OBJ_TYPE_INODE_FL; - - if (iter_info.type_mask & FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL) - fsnotify_iter_set_vfsmount_mark(&iter_info, - fsnotify_next_mark(iter_info.vfsmount_mark)); - else if (iter_info.vfsmount_mark) - iter_info.type_mask |= FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL; + fsnotify_iter_next(&iter_info); } ret = 0; out: -- 2.7.4