From patchwork Tue May 5 16:20:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED07017E8 for ; Tue, 5 May 2020 16:20:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D05AB20746 for ; Tue, 5 May 2020 16:20:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d+1BUMa6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730112AbgEEQU0 (ORCPT ); Tue, 5 May 2020 12:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729289AbgEEQUZ (ORCPT ); Tue, 5 May 2020 12:20:25 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F700C061A0F for ; Tue, 5 May 2020 09:20:24 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id e26so2945106wmk.5 for ; Tue, 05 May 2020 09:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8jteWdy5qLU814tl/j2JNd4yjbPoMjg+eGhjvanzjio=; b=d+1BUMa6j4dLF7fNl89xYa6+Arlko2NvBu+cqdBVyp/lhcHRGcExeVohXz4GRe+i/G D62QVNe81iqcUqMHJmsHoR5c4jug6eqnP1W88sBf6aBWjS4L0OSc5gWupFUaJFZclRwx 14lISYh1TyYw/7S+fzAu2sWJ0AB7GzWTdUjZbtOyBq1UispFXkzZ6PS0KwdB6E5FyDX8 bYP231Uc5cWnlBZdbz7SSmWD3qkJHUkJDCZR4i5SBOvc1b6bp1lqcmOY/N+xRp7Ew2s+ zqHtZD8Lnk5NCl0k6RjOpeNuk4TlPKoLPvfHEmNdbfh0O0c07gVKzTCF1HhgVx12FNks voEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8jteWdy5qLU814tl/j2JNd4yjbPoMjg+eGhjvanzjio=; b=nU6G0QcMQ5eJcUBXFfLqcSePkmLMy37DlM6S6D/hJ2DI8zLWRLnMXDsv42m3dvu6Dy 3HtLQbdzJrgpb4RUg+VusbD7iej0MQeqeTDmOV5ogIeThqVzhJLFbkgIP4VBSK+ydWkM mIX5X75RsgrJwYQ1tx8pT6RwOXW7oIiPgo471xzHqmdp5r2Zf7v2pjsrB3ks26Gi7+zv 2ZtEyqdgfIBtffmt4N2Qo9Bj0zYUtwnAIMfI4rKMKbODJWY0YWKyLo+Djq51cDS2PWdR //aWkQeJhK4jnjW594/yd0Uh8ZxZe8TT1zNCNz6SkVVOLe0UTIR7523H0lsCDdegaODH ySOQ== X-Gm-Message-State: AGi0PuYQTdB69mnv6xyM+vM1zzgyeS1/TlurhmhrFUIVJasw7DljWX39 YZbn82aq9D6CUUpa/BGD6Ek= X-Google-Smtp-Source: APiQypLHyEBB71jlibkgDazkGs6ksqrJIW6T7fPC0FwJV5B4k7Z7a3ZH+RRV6RclBVYG2n7xTakcLw== X-Received: by 2002:a1c:7f4e:: with SMTP id a75mr1651784wmd.178.1588695622993; Tue, 05 May 2020 09:20:22 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:22 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 1/7] fanotify: create overflow event type Date: Tue, 5 May 2020 19:20:08 +0300 Message-Id: <20200505162014.10352-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The special overflow event is allocated as struct fanotify_path_event, but with a null path. Use a special event type to identify the overflow event, so the helper fanotify_has_event_path() will always indicate a non null path. Allocating the overflow event doesn't need any of the fancy stuff in fanotify_alloc_event(), so create a simplified helper for allocating the overflow event. There is also no need to store and report the pid with an overflow event. Suggested-by: Jan Kara Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 27 +++++++++++---------------- fs/notify/fanotify/fanotify.h | 15 +++++++++------ fs/notify/fanotify/fanotify_user.c | 21 ++++++++++++++++----- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 5435a40f82be..ce4677077118 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -341,11 +341,11 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, return (struct inode *)fsnotify_data_inode(data, data_type); } -struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, - struct inode *inode, u32 mask, - const void *data, int data_type, - const struct qstr *file_name, - __kernel_fsid_t *fsid) +static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, + struct inode *inode, u32 mask, + const void *data, int data_type, + const struct qstr *file_name, + __kernel_fsid_t *fsid) { struct fanotify_event *event = NULL; struct fanotify_fid_event *ffe = NULL; @@ -423,8 +423,7 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, * event queue, so event reported on parent is merged with event * reported on child when both directory and child watches exist. */ - fsnotify_init_event(&event->fse, (unsigned long)id); - event->mask = mask; + fanotify_init_event(event, (unsigned long)id, mask); if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) event->pid = get_pid(task_pid(current)); else @@ -440,15 +439,8 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, fanotify_encode_fh(fanotify_event_dir_fh(event), id, gfp); if (fanotify_event_has_path(event)) { - struct path *p = fanotify_event_path(event); - - if (path) { - *p = *path; - path_get(path); - } else { - p->mnt = NULL; - p->dentry = NULL; - } + *fanotify_event_path(event) = *path; + path_get(path); } out: memalloc_unuse_memcg(); @@ -637,6 +629,9 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event) case FANOTIFY_EVENT_TYPE_FID_NAME: fanotify_free_name_event(event); break; + case FANOTIFY_EVENT_TYPE_OVERFLOW: + kfree(event); + break; default: WARN_ON_ONCE(1); } diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 35bfbf4a7aac..3adbb9f7d1a8 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -63,6 +63,7 @@ enum fanotify_event_type { FANOTIFY_EVENT_TYPE_FID_NAME, /* variable length */ FANOTIFY_EVENT_TYPE_PATH, FANOTIFY_EVENT_TYPE_PATH_PERM, + FANOTIFY_EVENT_TYPE_OVERFLOW, /* struct fanotify_event */ }; struct fanotify_event { @@ -72,6 +73,14 @@ struct fanotify_event { struct pid *pid; }; +static inline void fanotify_init_event(struct fanotify_event *event, + unsigned long id, u32 mask) +{ + fsnotify_init_event(&event->fse, id); + event->mask = mask; + event->pid = NULL; +} + struct fanotify_fid_event { struct fanotify_event fae; __kernel_fsid_t fsid; @@ -202,9 +211,3 @@ static inline struct path *fanotify_event_path(struct fanotify_event *event) else return NULL; } - -struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, - struct inode *inode, u32 mask, - const void *data, int data_type, - const struct qstr *file_name, - __kernel_fsid_t *fsid); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 42cb794c62ac..8c6d22ec7b41 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -829,13 +829,26 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, FSNOTIFY_OBJ_TYPE_INODE, mask, flags, fsid); } +static struct fsnotify_event *fanotify_alloc_overflow_event(void) +{ + struct fanotify_event *oevent; + + oevent = kmalloc(sizeof(*oevent), GFP_KERNEL_ACCOUNT); + if (!oevent) + return NULL; + + fanotify_init_event(oevent, 0, FS_Q_OVERFLOW); + oevent->type = FANOTIFY_EVENT_TYPE_OVERFLOW; + + return &oevent->fse; +} + /* fanotify syscalls */ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) { struct fsnotify_group *group; int f_flags, fd; struct user_struct *user; - struct fanotify_event *oevent; pr_debug("%s: flags=%x event_f_flags=%x\n", __func__, flags, event_f_flags); @@ -890,13 +903,11 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) atomic_inc(&user->fanotify_listeners); group->memcg = get_mem_cgroup_from_mm(current->mm); - oevent = fanotify_alloc_event(group, NULL, FS_Q_OVERFLOW, NULL, - FSNOTIFY_EVENT_NONE, NULL, NULL); - if (unlikely(!oevent)) { + group->overflow_event = fanotify_alloc_overflow_event(); + if (unlikely(!group->overflow_event)) { fd = -ENOMEM; goto out_destroy_group; } - group->overflow_event = &oevent->fse; if (force_o_largefile()) event_f_flags |= O_LARGEFILE; From patchwork Tue May 5 16:20:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 497BC81 for ; Tue, 5 May 2020 16:20:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C11220746 for ; Tue, 5 May 2020 16:20:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZyWQqhz0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730159AbgEEQU0 (ORCPT ); Tue, 5 May 2020 12:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgEEQUZ (ORCPT ); Tue, 5 May 2020 12:20:25 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09ACC061A10 for ; Tue, 5 May 2020 09:20:25 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id i10so3437028wrv.10 for ; Tue, 05 May 2020 09:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xy9jUkHXrFfGeZ2UC9pdb1nAElg/MaivsUkcZH3nGAA=; b=ZyWQqhz0YBtSvRHaahVsWQlIYCo5l5bHP12PJP+XphLYXMes61KKPXmmaxtS4f0BJv WLD3/LReEO7KS8Tw5gMyuT6tyL5XXsIqciK9yxvT58Hjb75TcM8Tkp20szCAngGSSekH EFkQHu7JXaQ8iQ3hXwtpIirOpX94/jJN9hU8WJpisWGRYMEYzdNY3NPhDcJA4p8Q3dvw 07Rx9eC06iHZ96oWKUlMNo4h+cNQViT5jjonUyclQ6WPAqKkYwh3FBcGgiE9GTkaSHo0 9yfvGirgc09ltwMp9v/TXS9Kj1MVCLsukSFDz6qQWj2T+TlkmyBh9237H5EmaK522X99 9fXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xy9jUkHXrFfGeZ2UC9pdb1nAElg/MaivsUkcZH3nGAA=; b=TX66P9prTSbyhgajsr6c3HbREJYgLRdiyAs8HSo/U6qiVX2SesH7CquG0ugVCqd6pJ /W/SamssMlQ4kgO49lfuNK9zUHV2yPFAa1w4gUjV5X4A1DhJwb1EwsT5Gz+jOC9FgVLL mx+ni+/9kTsuY/TdKtVoBLx1qtP//EN6K1uNsRU/q927NtxheXKmRsTNSnNbEj3UOggB Qpg5Rr2lLOVFkoSvX+bMdkQ9Y4TWrzDQc/w2QnN/bGGu2sp52WHXGb9sGipvbKX8JUYu enihvQeRGxUf2QIsIgkth40lv0LJAc+6j94FkoR5Kko7qiwaulwrNSAJDsVVEVEiNZ2L pJ8Q== X-Gm-Message-State: AGi0Pua+rUnXFleKfPQ9kKp7az9BkiJrGNiCafm9ZKWKkkumQk41VZqX 8q411lF/0fzkTgRV/vXSXY6yK++N X-Google-Smtp-Source: APiQypJp6/PAcQoGOi4GBb9szHV+Ef+QTSLPwUy/CUf0h1b52MkVJbmsLluIaSb/D7Dxmo/h4hiDJA== X-Received: by 2002:adf:f1c5:: with SMTP id z5mr4571582wro.100.1588695624364; Tue, 05 May 2020 09:20:24 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:23 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/7] fanotify: break up fanotify_alloc_event() Date: Tue, 5 May 2020 19:20:09 +0300 Message-Id: <20200505162014.10352-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Break up fanotify_alloc_event() into helpers by event struct type. Suggested-by: Jan Kara Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 146 ++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index ce4677077118..f5c21949fdaa 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -341,6 +341,77 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, return (struct inode *)fsnotify_data_inode(data, data_type); } +struct fanotify_event *fanotify_alloc_path_event(const struct path *path, + gfp_t gfp) +{ + struct fanotify_path_event *pevent; + + pevent = kmem_cache_alloc(fanotify_path_event_cachep, gfp); + if (!pevent) + return NULL; + + pevent->fae.type = FANOTIFY_EVENT_TYPE_PATH; + pevent->path = *path; + path_get(path); + + return &pevent->fae; +} + +struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, + gfp_t gfp) +{ + struct fanotify_perm_event *pevent; + + pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); + if (!pevent) + return NULL; + + pevent->fae.type = FANOTIFY_EVENT_TYPE_PATH_PERM; + pevent->response = 0; + pevent->state = FAN_EVENT_INIT; + pevent->path = *path; + path_get(path); + + return &pevent->fae; +} + +struct fanotify_event *fanotify_alloc_fid_event(struct inode *id, + __kernel_fsid_t *fsid, + gfp_t gfp) +{ + struct fanotify_fid_event *ffe; + + ffe = kmem_cache_alloc(fanotify_fid_event_cachep, gfp); + if (!ffe) + return NULL; + + ffe->fae.type = FANOTIFY_EVENT_TYPE_FID; + ffe->fsid = *fsid; + fanotify_encode_fh(&ffe->object_fh, id, gfp); + + return &ffe->fae; +} + +struct fanotify_event *fanotify_alloc_name_event(struct inode *id, + __kernel_fsid_t *fsid, + const struct qstr *file_name, + gfp_t gfp) +{ + struct fanotify_name_event *fne; + + fne = kmalloc(sizeof(*fne) + file_name->len + 1, gfp); + if (!fne) + return NULL; + + fne->fae.type = FANOTIFY_EVENT_TYPE_FID_NAME; + fne->fsid = *fsid; + fanotify_encode_fh(&fne->dir_fh, id, gfp); + fne->name_len = file_name->len; + strcpy(fne->name, file_name->name); + + return &fne->fae; +} + static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, struct inode *inode, u32 mask, const void *data, int data_type, @@ -348,8 +419,6 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, __kernel_fsid_t *fsid) { struct fanotify_event *event = NULL; - struct fanotify_fid_event *ffe = NULL; - struct fanotify_name_event *fne = NULL; gfp_t gfp = GFP_KERNEL_ACCOUNT; struct inode *id = fanotify_fid_inode(inode, mask, data, data_type); const struct path *path = fsnotify_data_path(data, data_type); @@ -369,55 +438,23 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, memalloc_use_memcg(group->memcg); if (fanotify_is_perm_event(mask)) { - struct fanotify_perm_event *pevent; - - pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); - if (!pevent) - goto out; - - event = &pevent->fae; - event->type = FANOTIFY_EVENT_TYPE_PATH_PERM; - pevent->response = 0; - pevent->state = FAN_EVENT_INIT; - goto init; - } - - /* - * For FAN_DIR_MODIFY event, we report the fid of the directory and - * the name of the modified entry. - * Allocate an fanotify_name_event struct and copy the name. - */ - if (mask & FAN_DIR_MODIFY && !(WARN_ON_ONCE(!file_name))) { - fne = kmalloc(sizeof(*fne) + file_name->len + 1, gfp); - if (!fne) - goto out; - - event = &fne->fae; - event->type = FANOTIFY_EVENT_TYPE_FID_NAME; - fne->name_len = file_name->len; - strcpy(fne->name, file_name->name); - goto init; - } - - if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { - ffe = kmem_cache_alloc(fanotify_fid_event_cachep, gfp); - if (!ffe) - goto out; - - event = &ffe->fae; - event->type = FANOTIFY_EVENT_TYPE_FID; + event = fanotify_alloc_perm_event(path, gfp); + } else if (mask & FAN_DIR_MODIFY && !(WARN_ON_ONCE(!file_name))) { + /* + * For FAN_DIR_MODIFY event, we report the fid of the directory + * and the name of the modified entry. + * Allocate an fanotify_name_event struct and copy the name. + */ + event = fanotify_alloc_name_event(id, fsid, file_name, gfp); + } else if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + event = fanotify_alloc_fid_event(id, fsid, gfp); } else { - struct fanotify_path_event *pevent; - - pevent = kmem_cache_alloc(fanotify_path_event_cachep, gfp); - if (!pevent) - goto out; - - event = &pevent->fae; - event->type = FANOTIFY_EVENT_TYPE_PATH; + event = fanotify_alloc_path_event(path, gfp); } -init: + if (!event) + goto out; + /* * Use the victim inode instead of the watching inode as the id for * event queue, so event reported on parent is merged with event @@ -429,19 +466,6 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, else event->pid = get_pid(task_tgid(current)); - if (fsid && fanotify_event_fsid(event)) - *fanotify_event_fsid(event) = *fsid; - - if (fanotify_event_object_fh(event)) - fanotify_encode_fh(fanotify_event_object_fh(event), id, gfp); - - if (fanotify_event_dir_fh(event)) - fanotify_encode_fh(fanotify_event_dir_fh(event), id, gfp); - - if (fanotify_event_has_path(event)) { - *fanotify_event_path(event) = *path; - path_get(path); - } out: memalloc_unuse_memcg(); return event; From patchwork Tue May 5 16:20:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0ECA481 for ; Tue, 5 May 2020 16:20:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAF29206B9 for ; Tue, 5 May 2020 16:20:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="apV54xOC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730134AbgEEQU2 (ORCPT ); Tue, 5 May 2020 12:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgEEQU1 (ORCPT ); Tue, 5 May 2020 12:20:27 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C02DC061A0F for ; Tue, 5 May 2020 09:20:27 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id e16so3462698wra.7 for ; Tue, 05 May 2020 09:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TCmf8C5nawtAUHiRXaKtNRxo3DSeSTT/sSmZUFizx28=; b=apV54xOCmRKRBZzNeClNPt1TdFfT4HlH618FqsXYaWDVYCnVbOswuP51vq1OSLf7nu F/p2wa2IeD9FajjLMyjdRYxVdJvFnE/fEavwLE83jAl05zSSxU7IZt1BjEF2rswAy4R/ dK2ZwGYL4MqTUiUVjNHmUvYxeSc72ku7evXA5MIe1xXQg574FGMw+O4MkxemcZG3P+Wq kQODPtEIgPH3aIASdcuE2XkgduwrmqnORNbtDMYNfmKumo+EiTiS7iZJwD6lCLNnDAeK EgeLQ3V3H2jk/ql3/Z1WFcsRE/j+cz3E0IYWMLa/aBJNrFvdJU3gcX9uapjQZzJDA/IE 2q8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TCmf8C5nawtAUHiRXaKtNRxo3DSeSTT/sSmZUFizx28=; b=td7YNBEyVx2UQY6VatOzwVT0yewO3LX8ofC3OmRBbkIhtPMLzzJEC2O1EzEGichKDZ h112P+n/wFjvJ+EdGoG6EWC3d6i2iCpD4x99vicXVidJBxa8BWD56SnfFx/r7DPWYZ1Q pk8ywVHJRZeXZo7J08cl4s6sTXbuiNEbXqmXEj+rmcPeR2+u87of8Il4gHX0Rm5xCMyb pvGwfbwd/SXYsRTOFlVzeD0vlMJMVovuC8K3MGELVFj1J9CC1u75S6saiao2hkZg3293 hJIGLClGaLnBcgwBCZRjrCp0cnHBUuqPdatPgoEh6B+9tsp3wHFnHUdy03LCu7pSmJsq Nskg== X-Gm-Message-State: AGi0PuZCDd2BuUBL2RH7e/FptK2vuch6WX8H722b9r5wlT5sOvs/IRWk gxFe6YeZe/WaTv0P6gLCfDFiv46r X-Google-Smtp-Source: APiQypKrCIAZEepr+QICFvMifhmzjtn4vCZOcu6jBenJIBfYe1yey0GJg6a3msgPJP61DCM+XJFIFw== X-Received: by 2002:adf:97de:: with SMTP id t30mr4721626wrb.135.1588695625827; Tue, 05 May 2020 09:20:25 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:25 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 3/7] fanotify: generalize the handling of extra event flags Date: Tue, 5 May 2020 19:20:10 +0300 Message-Id: <20200505162014.10352-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In fanotify_group_event_mask() there is logic in place to make sure we are not going to handle an event with no type and just FAN_ONDIR flag. Generalize this logic to any FANOTIFY_EVENT_FLAGS. There is only one more flag in this group at the moment, FAN_EVENT_ON_CHILD, and we will soon need to mask it out. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index f5c21949fdaa..1e4a345155dd 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -264,11 +264,11 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, * to user in FAN_REPORT_FID mode for all event types. */ if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { - /* Do not report FAN_ONDIR without any event */ - if (!(test_mask & ~FAN_ONDIR)) + /* Do not report event flags without any event */ + if (!(test_mask & ~FANOTIFY_EVENT_FLAGS)) return 0; } else { - user_mask &= ~FAN_ONDIR; + user_mask &= ~FANOTIFY_EVENT_FLAGS; } return test_mask & user_mask; From patchwork Tue May 5 16:20:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B9FF913 for ; Tue, 5 May 2020 16:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F84220746 for ; Tue, 5 May 2020 16:20:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LPeObwI2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730222AbgEEQUb (ORCPT ); Tue, 5 May 2020 12:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730056AbgEEQU3 (ORCPT ); Tue, 5 May 2020 12:20:29 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E34C061A0F for ; Tue, 5 May 2020 09:20:28 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id u127so3019066wmg.1 for ; Tue, 05 May 2020 09:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2ofUnhNRHIzcaSUijq5Z6dGV0CsGnW2PMJHsRfB+wRw=; b=LPeObwI2Z3tc2eoz472K3ToHnSxcdfr/YP9nf1tz8TjzB3KLLTsk7mEdleEDYsBFbW 61Sm1DJwqP8+rf7JajW0rR3p4ZboLOxp/erwcP9AJoftyMrwcJNy1SoAvSF+03PTuuY5 yMLe3taSdvzzzboS/PZ2ckey6MsAniTeerysVIE0h2WMalxIaMIenPx2VfOcZTczCGGu pwlrW7VefWS9T6hkmSimWLyyYY59O7V0MjyAufvGo9ctJXpkmZwosGdVBTjSUeHJZKgV q/mPiBUgoG5JQWb0wvCPIsnCLR0YsGfimXDGOLbOau/S+aazIECi7fy8AGCYAI89XM89 r1XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2ofUnhNRHIzcaSUijq5Z6dGV0CsGnW2PMJHsRfB+wRw=; b=O0Kxj/QPXzv2lJxqwBi1C4h7AIPog/1jM7aexwd9P2JM8/99PuX03QRHzSFtxYO1YF 6LedlLB8CzHtV0w+pNRg3qlsaPzfCOr0fKTbWGJ7I2GFXe74WH9bN5qUDeV2IoXKtbZp Af33oOTHmyCgKsKjBVua056CcKKwzeUMDcsU7dA0XDI5Sq7HRoQbquEpOINezv/RQCUJ CssPch85t5kwyccFFkWHUdU16wEOADXspIggmxQOLH3rHeEZ2vxsiFfrEh/JrlBIzx5B BtrwYx0XKb0hvEo9abEk17X/sQTxjY6EV2THsRuhb75MQ2hbk3/SgX/DuDH+qjIXI1S4 hW/w== X-Gm-Message-State: AGi0PuYg0dC5SlujAhi0nAs6GPnNO0q3BCl1xR/4X0KkcGp7imlzHOAW iZiMN4JsI42/EjO9GhzJ9Ps= X-Google-Smtp-Source: APiQypLjYFs21If/AXmYdmA3/IX31+7SHKw+IK4cN/FEWiBjNlZq9erW8626p+bj7wXfqh+2B7izWg== X-Received: by 2002:a1c:3dd6:: with SMTP id k205mr4327137wma.138.1588695627407; Tue, 05 May 2020 09:20:27 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:26 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 4/7] fanotify: distinguish between fid encode error and null fid Date: Tue, 5 May 2020 19:20:11 +0300 Message-Id: <20200505162014.10352-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In fanotify_encode_fh(), both cases of NULL inode and failure to encode ended up with fh type FILEID_INVALID. Distiguish the case of NULL inode, by setting fh type to FILEID_ROOT. This is needed because fanotify_fh_equal() treats FILEID_INVALID specially and we are going to need fanotify_fh_equal() to return true when comparing two null fids. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 1e4a345155dd..bdafc76cc258 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -282,8 +282,11 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, void *buf = fh->buf; int err; + /* FAN_DIR_MODIFY does not encode object fh */ + fh->type = FILEID_ROOT; + fh->len = 0; if (!inode) - goto out; + return; dwords = 0; err = -ENOENT; @@ -318,7 +321,6 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, type, bytes, err); kfree(ext_buf); *fanotify_fh_ext_buf_ptr(fh) = NULL; -out: /* Report the event without a file identifier on encode error */ fh->type = FILEID_INVALID; fh->len = 0; From patchwork Tue May 5 16:20:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4DBC17E8 for ; Tue, 5 May 2020 16:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8C3B20746 for ; Tue, 5 May 2020 16:20:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZNpVYstL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730242AbgEEQUb (ORCPT ); Tue, 5 May 2020 12:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgEEQUa (ORCPT ); Tue, 5 May 2020 12:20:30 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 481DAC061A10; Tue, 5 May 2020 09:20:30 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id e16so3462885wra.7; Tue, 05 May 2020 09:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yFtMzdlVERg3W0V/nBQMM7T1KqaZRn4iadefSm9BaJs=; b=ZNpVYstLVUqqv4tOCIkPr1wjpgsGXAUVfCd0fg0c8izBlRU1zVw782DYAkBGSlIPDb KDYiT8LGCTHEX6XUBIS5xPaz+TUnKKp8UlD/64JgMADSdhTwSfTfAN/VdrB7mQSY5oRn Z6IXmlg++rj5nmwxOzPAcmMIaId4/2XLN5qL2G08Ki5Wf1TCFsmBLB2jOFegbZ/dwOeE HW02tNSmySUTslRZe4sv+R3K0WgID4o3dR2khmpfpBC3kZnIfuir0vS1pBTewteEmpNM sTdBnOgboZa6RorkAYkSXRGxAq30Hg0ueR+RnYwbRXuKBKHZUqKkuoV1lQ/3jrMUM/kV m59A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yFtMzdlVERg3W0V/nBQMM7T1KqaZRn4iadefSm9BaJs=; b=OFGrq9I5bTuJ2UAznpsJhiZ3t1XxxTMvfz5UxjMwseK+8C8ATgL1kZQRJwH/XTUQX3 99qdhg5DGBGqVB2587Nq/fa9gPJP6PDhXLYZ3SIye4vvtBjDGyy6dXKqtsJ0oTb7SyU3 Z/V9VyYzXWiutxRABtek5UckcP4yFUagEMhjxL+iwjXbzc7AeDoOehYQf6n0yHr0koSx 4tpV2uLweJWFN4dE1RGv7h5cjwIAu8m6jtXOgTwRMyHWKDJx97rSTO0EBaHDfI6mpdvs GuiqNTf7XgHsW4YpYqwHRJ+M6qWXxutX+VzvFBfqeW/Kqga2+n2PbocfgPby8yaDtGwh UirA== X-Gm-Message-State: AGi0PuZkKh+5s074aXf14c1Un+wsWL31WrsgA8Zcg4FhgmhRUx40qsP+ sgpWUvkc+L3yBXA4p8QKL7GxBG7y X-Google-Smtp-Source: APiQypKwRxXSWs0PLLw+2kd4wvZ7y2ucebRLh7WFhiCBTmA4gjrFONKCYFVbXB39CkGO9LURDM5pmg== X-Received: by 2002:adf:e450:: with SMTP id t16mr4906034wrm.301.1588695628883; Tue, 05 May 2020 09:20:28 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:28 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v3 5/7] fanotify: report parent fid + name for events on children Date: Tue, 5 May 2020 19:20:12 +0300 Message-Id: <20200505162014.10352-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org An application that needs to index or mirror the content of a large directory needs an efficient way to be notified on changes in that directory without re-scanning the entire directory on every change. The event FAN_DIR_MODIFY provides the means to get a notification on directory entry changes, but not on child modifications. fanotify provides the capability to get events on changes to children of a watched directory, but getting the name of the child is not reliable and this is something that an application of that sort needs. As a matter of fact, inotify already provides this capability, but it does not scale to watching the entire filesystem. We are adding the basic capability to fanotify only for directory marks for now and soon we will add the ability to watch an entire filesystem or mount with a reliable [*] way to get the path on the event. [*] reliable above means that we can stat the file by dirfid+name and know for sure of the event reported was for that file. A new fanotify_init() flag FAN_REPORT_NAME is introduced. It requires flag FAN_REPORT_FID and there is a constant for setting both flags named FAN_REPORT_FID_NAME. For a group with fanotify_init() flag FAN_REPORT_NAME, the parent fid and name are reported for events "on child" to a directory watching children. The parent fid and name are reported with an info record of type FAN_EVENT_INFO_TYPE_DFID_NAME, similar to the way that name info is reported for FAN_DIR_MODIFY events. The child fid itself is reported with another info record of type FAN_EVENT_INFO_TYPE_FID that follows the first info record, with the same fid info as reported to a group with only FAN_REPORT_FID flag. FAN_DIR_MODIFY events do not record nor report the "child" fid, but in order to stay consistent with events "on child", we store those events in struct fanotify_name_event with an empty object_fh. This wastes a few unused bytes (16) of memory per FAN_DIR_MODIFY event, but keeps the code simpler and avoids creating a custom event struct just for FAN_DIR_MODIFY events. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 33 ++++++++++++++++++++++++------ fs/notify/fanotify/fanotify.h | 3 +++ fs/notify/fanotify/fanotify_user.c | 6 +++++- include/linux/fanotify.h | 2 +- include/uapi/linux/fanotify.h | 4 ++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index bdafc76cc258..e91a8cc1b83c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -64,7 +64,8 @@ static bool fanotify_name_event_equal(struct fanotify_name_event *fne1, return false; if (fne1->name_len != fne2->name_len || - !fanotify_fh_equal(&fne1->dir_fh, &fne2->dir_fh)) + !fanotify_fh_equal(&fne1->dir_fh, &fne2->dir_fh) || + !fanotify_fh_equal(&fne1->object_fh, &fne2->object_fh)) return false; return !memcmp(fne1->name, fne2->name, fne1->name_len); @@ -211,7 +212,8 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, int data_type) { __u32 marks_mask = 0, marks_ignored_mask = 0; - __u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS; + __u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS | + FANOTIFY_EVENT_FLAGS; const struct path *path = fsnotify_data_path(data, data_type); struct fsnotify_mark *mark; int type; @@ -262,11 +264,17 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, * For backward compatibility and consistency, do not report FAN_ONDIR * to user in legacy fanotify mode (reporting fd) and report FAN_ONDIR * to user in FAN_REPORT_FID mode for all event types. + * + * We never report FAN_EVENT_ON_CHILD to user, but we do pass it in to + * fanotify_alloc_event() for group with FAN_REPORT_NAME as indication + * of how the event should be reported. */ if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { /* Do not report event flags without any event */ if (!(test_mask & ~FANOTIFY_EVENT_FLAGS)) return 0; + if (!FAN_GROUP_FLAG(group, FAN_REPORT_NAME)) + user_mask &= ~FAN_EVENT_ON_CHILD; } else { user_mask &= ~FANOTIFY_EVENT_FLAGS; } @@ -394,10 +402,10 @@ struct fanotify_event *fanotify_alloc_fid_event(struct inode *id, return &ffe->fae; } -struct fanotify_event *fanotify_alloc_name_event(struct inode *id, +struct fanotify_event *fanotify_alloc_name_event(struct inode *dir, __kernel_fsid_t *fsid, const struct qstr *file_name, - gfp_t gfp) + struct inode *id, gfp_t gfp) { struct fanotify_name_event *fne; @@ -407,7 +415,8 @@ struct fanotify_event *fanotify_alloc_name_event(struct inode *id, fne->fae.type = FANOTIFY_EVENT_TYPE_FID_NAME; fne->fsid = *fsid; - fanotify_encode_fh(&fne->dir_fh, id, gfp); + fanotify_encode_fh(&fne->dir_fh, dir, gfp); + fanotify_encode_fh(&fne->object_fh, id, gfp); fne->name_len = file_name->len; strcpy(fne->name, file_name->name); @@ -447,7 +456,17 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, * and the name of the modified entry. * Allocate an fanotify_name_event struct and copy the name. */ - event = fanotify_alloc_name_event(id, fsid, file_name, gfp); + event = fanotify_alloc_name_event(id, fsid, file_name, NULL, + gfp); + } else if (FAN_GROUP_FLAG(group, FAN_REPORT_NAME) && + (mask & FAN_EVENT_ON_CHILD) && likely(inode != id)) { + /* + * With flag FAN_REPORT_NAME, we report the parent fid and name + * for events reported "on child" in addition to reporting the + * child fid. + */ + event = fanotify_alloc_name_event(inode, fsid, file_name, id, + gfp); } else if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { event = fanotify_alloc_fid_event(id, fsid, gfp); } else { @@ -631,6 +650,8 @@ static void fanotify_free_name_event(struct fanotify_event *event) { struct fanotify_name_event *fne = FANOTIFY_NE(event); + if (fanotify_fh_has_ext_buf(&fne->object_fh)) + kfree(fanotify_fh_ext_buf(&fne->object_fh)); if (fanotify_fh_has_ext_buf(&fne->dir_fh)) kfree(fanotify_fh_ext_buf(&fne->dir_fh)); kfree(fne); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 3adbb9f7d1a8..9aafccc23c75 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -96,6 +96,7 @@ FANOTIFY_FE(struct fanotify_event *event) struct fanotify_name_event { struct fanotify_event fae; __kernel_fsid_t fsid; + struct fanotify_fh object_fh; struct fanotify_fh dir_fh; u8 name_len; char name[0]; @@ -122,6 +123,8 @@ static inline struct fanotify_fh *fanotify_event_object_fh( { if (event->type == FANOTIFY_EVENT_TYPE_FID) return &FANOTIFY_FE(event)->object_fh; + else if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME) + return &FANOTIFY_NE(event)->object_fh; else return NULL; } diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8c6d22ec7b41..030534da49e2 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -879,6 +879,10 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) (flags & FANOTIFY_CLASS_BITS) != FAN_CLASS_NOTIF) return -EINVAL; + /* Child name is reported with parent fid */ + if ((flags & FAN_REPORT_NAME) && !(flags & FAN_REPORT_FID)) + return -EINVAL; + user = get_current_user(); if (atomic_read(&user->fanotify_listeners) > FANOTIFY_DEFAULT_MAX_LISTENERS) { free_uid(user); @@ -1212,7 +1216,7 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark, */ static int __init fanotify_user_setup(void) { - BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 8); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 9); BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 3049a6c06d9e..5412a25c54c0 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -19,7 +19,7 @@ FAN_CLASS_PRE_CONTENT) #define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ - FAN_REPORT_TID | FAN_REPORT_FID | \ + FAN_REPORT_TID | FAN_REPORT_FID_NAME | \ FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index a88c7c6d0692..41f54a0f360f 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -54,6 +54,10 @@ /* Flags to determine fanotify event format */ #define FAN_REPORT_TID 0x00000100 /* event->pid is thread id */ #define FAN_REPORT_FID 0x00000200 /* Report unique file id */ +#define FAN_REPORT_NAME 0x00000400 /* Report events with name */ + +/* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_FID */ +#define FAN_REPORT_FID_NAME (FAN_REPORT_FID | FAN_REPORT_NAME) /* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ From patchwork Tue May 5 16:20:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E733F81 for ; Tue, 5 May 2020 16:20:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD03120836 for ; Tue, 5 May 2020 16:20:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rvRKFBU7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730274AbgEEQUd (ORCPT ); Tue, 5 May 2020 12:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgEEQUc (ORCPT ); Tue, 5 May 2020 12:20:32 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02D4FC061A0F for ; Tue, 5 May 2020 09:20:32 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id h4so2959525wmb.4 for ; Tue, 05 May 2020 09:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6TzAOBWWwqsbBXCjafLP2an/PhS60lundPWCqLj6zO8=; b=rvRKFBU7hatLcWtNkbsNrxmrGtk3WzDbapIwlxBqXS1fbg0zuqZ34gd0uvFsfYzOpc CeR5aJ7o8+Wb+F3hUp3nE92ClMMN2DYJ/MhwQvfqRVfo7hR2nOlL0TuiqkjDPROWGeVD rqgNObHA18iwzFLLZ1i3FoZd7e08+u/xPRVNKkBijf9hkzFg3l00SwVvGMF8TbxAVXma mbntUT4qehe/i1gay/Ds58H8QO5cogX24+IlwFNFwyzcpFGvyIBGCb//GBOUshdoma9f h2wGxb2Su5vJ0UHzADW70/egE0Kl7SYn3T2IvRX3+XWHi8IhP3jk/PD/4+dzN2mr5o5I k+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6TzAOBWWwqsbBXCjafLP2an/PhS60lundPWCqLj6zO8=; b=jYwbpZmMAI1aIwk/zmar0b1k887S64mVNJAqKHoND3LD933EgjuPDd35+sCGM7IB6l FZnyxKSbVyQUX4Ux+ylRi1QvMuSPB5N3x3Yz9Q+9rxvYcuMklPbrdf2Y3fJrWqsY3ox/ rtW1GzIJYN8V717WvlsModdAJcNO1jrIkeW/GE1kZJassaSe2Vicekwr6QJf9pmvxMFp FgSPXL7v6LXQPkAyhXyUlaPxDV4uRz9YaIm+A47D/hTnQitLiuhGQ8dzCNNTnx9TP9X6 u3igLfNkAh9DBtQFFmG85PE7jQnrQ4a+Dp+5hv1gUkWhxW/KI3ChWyMzsvjLqUQDSDzj UwPA== X-Gm-Message-State: AGi0PubxO+PshoEBqSwQXOf1kM9n83xxU1gQ59OoFoH/OV6vKURHqLft eVDOlczTpnunsscQT9SCIQY= X-Google-Smtp-Source: APiQypKkGp3JhQgBn5krgMR+SoZnkXQ000DS71PiHATXCUQGH2tkHPbM80xFQ++97NIW0UwVzD8ktw== X-Received: by 2002:a05:600c:441a:: with SMTP id u26mr4585355wmn.154.1588695630610; Tue, 05 May 2020 09:20:30 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:30 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v3 6/7] fsnotify: send event "on child" to sb/mount marks Date: Tue, 5 May 2020 19:20:13 +0300 Message-Id: <20200505162014.10352-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Similar to events "on child" to watching directory, send event flavor "on child" to sb/mount marks that specified interest in this flavor. Event "on child" will not be sent on "orphan" children, that is, on disconnected dentries and on a mount/sb root. Currently, fanotify allows to set the FAN_EVENT_ON_CHILD flag on sb/mount marks, but it was ignored. Mask the flag explicitly until fanotify implements support for events "on child" with name info for sb/mount marks. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 7 ++++-- fs/notify/fsnotify.c | 38 ++++++++++++++++++++++++------ include/linux/fsnotify_backend.h | 23 ++++++++++++------ 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 030534da49e2..36c1327b32f4 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1146,10 +1146,13 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, } /* inode held in place by reference to path; group by fget on fd */ - if (mark_type == FAN_MARK_INODE) + if (mark_type == FAN_MARK_INODE) { inode = path.dentry->d_inode; - else + } else { mnt = path.mnt; + /* Mask out FAN_EVENT_ON_CHILD flag for sb/mount marks */ + mask &= ~FAN_EVENT_ON_CHILD; + } /* create/update an inode mark */ switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) { diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 72d332ce8e12..f6da8f263bc0 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -142,23 +142,50 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) spin_unlock(&inode->i_lock); } -/* Notify this dentry's parent about a child's events. */ +/* + * Notify this dentry's parent about a child's events if parent is watching + * children or if sb/mount marks are interested in events with file_name info. + */ int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type) { + const struct path *path = fsnotify_data_path(data, data_type); + struct mount *mnt = NULL; + bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED; + __u32 test_mask = mask & FS_EVENTS_POSS_ON_CHILD; + __u32 p_mask, marks_mask = 0; struct dentry *parent; struct inode *p_inode; int ret = 0; - if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) + if (path && path->mnt->mnt_root != dentry) + mnt = real_mount(path->mnt); + + /* + * FS_EVENT_ON_CHILD on sb/mount mask implies reporting events as if all + * directories are watched. + */ + if (!IS_ROOT(dentry)) + marks_mask |= fsnotify_watches_children( + dentry->d_sb->s_fsnotify_mask); + if (mnt) + marks_mask |= fsnotify_watches_children( + mnt->mnt_fsnotify_mask); + + + if (!(marks_mask & test_mask) && !parent_watched) return 0; parent = dget_parent(dentry); p_inode = parent->d_inode; + p_mask = fsnotify_inode_watches_children(p_inode); - if (unlikely(!fsnotify_inode_watches_children(p_inode))) { + if (p_mask) + marks_mask |= p_mask; + else if (unlikely(parent_watched)) __fsnotify_update_child_dentry_flags(p_inode); - } else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) { + + if (marks_mask & test_mask) { struct name_snapshot name; /* we are notifying a parent so come up with the new mask which @@ -323,9 +350,6 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, mnt = real_mount(path->mnt); mnt_or_sb_mask |= mnt->mnt_fsnotify_mask; } - /* An event "on child" is not intended for a mount/sb mark */ - if (mask & FS_EVENT_ON_CHILD) - mnt_or_sb_mask = 0; /* * Optimization: srcu_read_lock() has a memory barrier which can diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index f0c506405b54..ca461b95662a 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -50,8 +50,12 @@ #define FS_DIR_MODIFY 0x00080000 /* Directory entry was modified */ #define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */ -/* This inode cares about things that happen to its children. Always set for - * dnotify and inotify. */ +/* + * This inode cares about things that happen to its children. + * Always set for dnotify and inotify. + * Set on sb/mount marks mask to indicate interest in getting events with + * file_name information. + */ #define FS_EVENT_ON_CHILD 0x08000000 #define FS_DN_RENAME 0x10000000 /* file renamed */ @@ -386,14 +390,19 @@ extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); extern void fsnotify_sb_delete(struct super_block *sb); extern u32 fsnotify_get_cookie(void); -static inline int fsnotify_inode_watches_children(struct inode *inode) +static inline __u32 fsnotify_watches_children(__u32 mask) { - /* FS_EVENT_ON_CHILD is set if the inode may care */ - if (!(inode->i_fsnotify_mask & FS_EVENT_ON_CHILD)) + /* FS_EVENT_ON_CHILD is set if the object may care */ + if (!(mask & FS_EVENT_ON_CHILD)) return 0; - /* this inode might care about child events, does it care about the + /* This object might care about child events, does it care about the * specific set of events that can happen on a child? */ - return inode->i_fsnotify_mask & FS_EVENTS_POSS_ON_CHILD; + return mask & FS_EVENTS_POSS_ON_CHILD; +} + +static inline int fsnotify_inode_watches_children(struct inode *inode) +{ + return fsnotify_watches_children(inode->i_fsnotify_mask); } /* From patchwork Tue May 5 16:20:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11529631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A62F913 for ; Tue, 5 May 2020 16:20:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 401A920735 for ; Tue, 5 May 2020 16:20:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q3tPb65j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730326AbgEEQUf (ORCPT ); Tue, 5 May 2020 12:20:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730038AbgEEQUe (ORCPT ); Tue, 5 May 2020 12:20:34 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFBFFC061A0F; Tue, 5 May 2020 09:20:33 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id s8so3437848wrt.9; Tue, 05 May 2020 09:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yY+bhdyqnSifK57VkgUaPiCviPA6iwmvsO4o134EEgY=; b=q3tPb65jrzPiiIZbzkr4Euc4VQeZgXUQahl8mWUCu0+ehoR4bgBIcRGTqiED3bOHAq h/wF/DwkciN3e02ugWRf1nT40NLTlrW4To6qZBwR30RYADHBpA4Cmp724RI2i+olMQFu 1+JOa3toBut+vY1QwASjGgnRxwBIyGQZdi8Ir6yrOif6OAmA2gRgt89ue1AveMKHow2n AqKrjvDn2V3Qare7XGd9tlO+timzPzE0pskXDUNzvaeLVjxQulxKDXEKoYeL6fuELqeA UvBA3WYlSpx618RXATwCmH/s5i1Wy/NEQ4/vw69pHbHgKGKw7gJm4fzcr7y/jREfz/+/ 2cWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yY+bhdyqnSifK57VkgUaPiCviPA6iwmvsO4o134EEgY=; b=o//Xml67migyVr+FvkWohD48sqA3NjAkk3AbuchjXg0++MO4ns/gigtK1HS6XrOO4f NeSpJNZUkrQffQFITvI9VuvK+62EbJXnTx2EDeVWyrkOAhdXQ0bcaCNN14eP28HZhGIE Ogkbp/ph7d1Nq2mxYsMJ7ZVJNmtI9PczowUgCpiTsKYG+T+Xl2M6A+0L+fzx9L2YoDbI xZ87JVe5boNExCSp6upcjniIWjoRAv6/9ssLHtxkYF5LUcxIDbdr0VEQsWYpsjBeruqm mTjQiGMzYBWx3al2dT1nYxvTbQsY/EhC6AHFtz3/HYoubx/LW461/soiWcnEUDJQ+DNC +2Sw== X-Gm-Message-State: AGi0PuZaYv6bgXeetpa3dT6FpYjolmOSQKTUlw8S94WxD4uotbJVt472 g+nST2G6e1g6EF8FAN7/HPQ= X-Google-Smtp-Source: APiQypKgEhgof7rSvYj3ILm/nrUjR72kkGB2LTvsUxaoRw3h7amXLD9kV0taO7xWOhMk55qpv/O3gg== X-Received: by 2002:a5d:614b:: with SMTP id y11mr4904778wrt.77.1588695632481; Tue, 05 May 2020 09:20:32 -0700 (PDT) Received: from localhost.localdomain ([141.226.12.123]) by smtp.gmail.com with ESMTPSA id c128sm1612871wma.42.2020.05.05.09.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 09:20:31 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v3 7/7] fanotify: report events "on child" with name info to sb/mount marks Date: Tue, 5 May 2020 19:20:14 +0300 Message-Id: <20200505162014.10352-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200505162014.10352-1-amir73il@gmail.com> References: <20200505162014.10352-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org With fanotify_init() flags FAN_REPORT_FID_NAME, when adding an inode mark with FS_EVENT_ON_CHILD, events are reported with fid of the parent and the name of the child entry. When adding a filesystem or mount mark, report events that are "possible on child" (e.g. open/close) in two flavors, one with just the child fid and one also with the parent fid and the child entry name, as if all directories are interested in events "on child". The flag FAN_EVENT_ON_CHILD was always ignored for sb/mount mark, so we can safely ignore the value of the flag passed by the user and set the flag in sb/mount mark mask depending on the FAN_REPORT_NAME group flag. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 7 +++++-- fs/notify/fanotify/fanotify_user.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index e91a8cc1b83c..ec42c721850c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -244,10 +244,13 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, /* * If the event is for a child and this mark doesn't care about * events on a child, don't send it! + * An event "on child" without name info is not intended for a + * mount/sb mark. */ if (event_mask & FS_EVENT_ON_CHILD && - (type != FSNOTIFY_OBJ_TYPE_INODE || - !(mark->mask & FS_EVENT_ON_CHILD))) + (!(mark->mask & FS_EVENT_ON_CHILD) || + (type != FSNOTIFY_OBJ_TYPE_INODE && + !FAN_GROUP_FLAG(group, FAN_REPORT_NAME)))) continue; marks_mask |= mark->mask; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 36c1327b32f4..89c0554da90e 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1150,8 +1150,20 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, inode = path.dentry->d_inode; } else { mnt = path.mnt; - /* Mask out FAN_EVENT_ON_CHILD flag for sb/mount marks */ - mask &= ~FAN_EVENT_ON_CHILD; + /* + * So far, flag FAN_EVENT_ON_CHILD was ignored for sb/mount + * marks. Reporting events "on child" with name info for + * sb/mount marks is now implemented, so explicitly mask out + * the flag for backward compatibility with existing programs + * that do not request events with name info. + * On sb/mount mark events with FAN_REPORT_NAME, events are + * reported as if all directories are interested in events + * "on child". + */ + if (FAN_GROUP_FLAG(group, FAN_REPORT_NAME)) + mask |= FAN_EVENT_ON_CHILD; + else + mask &= ~FAN_EVENT_ON_CHILD; } /* create/update an inode mark */