From patchwork Tue Jan 14 15:16:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332475 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 E977A1398 for ; Tue, 14 Jan 2020 15:17:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5DD924680 for ; Tue, 14 Jan 2020 15:17:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QGN82Wcu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbgANPRF (ORCPT ); Tue, 14 Jan 2020 10:17:05 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40326 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgANPRF (ORCPT ); Tue, 14 Jan 2020 10:17:05 -0500 Received: by mail-wr1-f66.google.com with SMTP id c14so12546513wrn.7 for ; Tue, 14 Jan 2020 07:17:03 -0800 (PST) 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=LxZjALu8+JdM1LNMX2SUCsKVBqP/y1yL79+aF6PkR+s=; b=QGN82Wcugzm4KOV7mdzrd2Y1nkklF+f8yQYPgDNMoOdpX+rW4TP/CStsKMqCbDlTaW hZcPmMBtEO7C9Xxg/ydEi+b+YgEK1NCo9WPTlibc/+QgEJJVRCWZ78gEmDQGyByW+KIZ EJaCRnsRymiQjqT+jPUl0cItfEv3T8mDuKWN/R8lXUppuzm5kH7tGaqlqYd0D0c9Y5+i Ngc7+tXNqYP4Ig1+twdI7bob7Zzcl9FTLJGtHFtxQxdWyJmNfkN4SQjKHiGgHD80NVqV 1YBZBtSn0gtu/A/egLY3Yp7T/g+D4VNzg5q2gha4BlNdq7K8A5NOtNHO7AMSpLSZuOFc cl2g== 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=LxZjALu8+JdM1LNMX2SUCsKVBqP/y1yL79+aF6PkR+s=; b=c3+N8nJzDDSMcWAejcluGnZz8yfJQ34RjFfa8h7voLFxxgStcDS6GPhyC2/a8wfwNc L5CtPWdO3m/tcflUz7q3e4YCQ1mMVUP3DLuXd9GG8669Ni3sR23hUGZuLxmuRVZ7e5Ry DWd0y82nU0wlX7ESGd0eR0VTx9YSDSHJn/DWGp8KfNj/XlRY7OFPjBmyAjQIjfkj/sOl tSw3Y+LNntpNEjNaG7BTeJbJpuuVe7uJjr0PPUkmTJ/49Zr5LZgTw3SkHsgqVH7FdI7r JX3P8PXHXpKfD2PPwMmn5ga1NizdVKT2KaJN+7yQnXCP9bbn4XkE/8JwcrUDxpU00/PU KrqA== X-Gm-Message-State: APjAAAXEEx3VMgKf6IudWIJvCab0buTBA40Paejg2NAZWRHmARdexq5s 42IR5fS3cpYUiWq7BJRuSr0= X-Google-Smtp-Source: APXvYqyM6mBR/xxcLJ+1wNSVE+c/dI7jN/himFdGC58ugdDeykc5LitqL+PsuclVJlJF/cx+uRybOQ== X-Received: by 2002:a5d:494b:: with SMTP id r11mr25822874wrs.184.1579015023141; Tue, 14 Jan 2020 07:17:03 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:02 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 1/6] fsnotify: tidy up FS_ and FAN_ constants Date: Tue, 14 Jan 2020 17:16:50 +0200 Message-Id: <20200114151655.29473-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Order by value, so the free value ranges are easier to find. Signed-off-by: Amir Goldstein --- include/linux/fsnotify_backend.h | 11 +++++------ include/uapi/linux/fanotify.h | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 1915bdba2fad..db3cabb4600e 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -49,16 +49,15 @@ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ #define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */ -#define FS_ISDIR 0x40000000 /* event occurred against dir */ -#define FS_IN_ONESHOT 0x80000000 /* only send event once */ - -#define FS_DN_RENAME 0x10000000 /* file renamed */ -#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */ - /* This inode cares about things that happen to its children. Always set for * dnotify and inotify. */ #define FS_EVENT_ON_CHILD 0x08000000 +#define FS_DN_RENAME 0x10000000 /* file renamed */ +#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */ +#define FS_ISDIR 0x40000000 /* event occurred against dir */ +#define FS_IN_ONESHOT 0x80000000 /* only send event once */ + #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) /* diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index b9effa6f8503..2a1844edda47 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -25,9 +25,9 @@ #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ -#define FAN_ONDIR 0x40000000 /* event occurred against dir */ +#define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ -#define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ +#define FAN_ONDIR 0x40000000 /* Event occurred against dir */ /* helper events */ #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ From patchwork Tue Jan 14 15:16:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332477 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 2B33792A for ; Tue, 14 Jan 2020 15:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F390024680 for ; Tue, 14 Jan 2020 15:17:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iorv8Ees" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbgANPRG (ORCPT ); Tue, 14 Jan 2020 10:17:06 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34149 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbgANPRF (ORCPT ); Tue, 14 Jan 2020 10:17:05 -0500 Received: by mail-wr1-f67.google.com with SMTP id t2so12572289wrr.1 for ; Tue, 14 Jan 2020 07:17:04 -0800 (PST) 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=H/wb/9PcQcjDLZR1CpEvba/9unOTmGL87G16ihlKy8A=; b=iorv8EesgUW61Q/FLsMJnclOEoohxYvP+yAT5SmibWJXuTWG23hfFpIFr7OtOXAl7/ e1VCE0ieQf6/pIuVVwst2xyFFIxCjNUIr9NrVdmQJsWrqbGG2kBDyDXssjaMcqljrjpm ieL9A4L6dncxG2wDCC8zSYIyDCKHi/V0490o+CfwymWrJJ0IkdJ5UjHs6yy5DKmnL+Vx 0TOA4seBVIv87SQ0vh1UamL0as3kit5MQ1i+XukeKTTDpN9cHBMFeLialB2S5n7pEqPt 7X/TgR8iYoCLL6M6h4/rwrD1JBXzPBsnLFEbbA48jJiF/cRJgg8LuyRUnqnTOJ3BpXEf /zJQ== 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=H/wb/9PcQcjDLZR1CpEvba/9unOTmGL87G16ihlKy8A=; b=nPkCxP2PCkfgq1s8kupUtd8WIKbwlljv1JFA/ou9bTGayWPNiKCwIzag7XI+amJVzs B6lRlMxVzButCIL1A4WspNv1ntpadKc8OX8ZtDBmv+7wOTaMxvKCdI1CTj3FxbwJW5C0 4oD/CSc7Ah0adGDVLN1gFMn9+cucQUzMsCY29KVj8V6qWfPEB9MGFi7S+dmEHMn+w/Gn ++aOptaPrYCnasr9vbKkxEsM/fcLTctYzRPK0FyBShLwxiLDsWGIIl0VIc4mxgxOHuGe 3nqMgkze6QWsbNEzd4wjRdIaMjuntTcErxqthsKrv2hGkVEUMSS23Xl5aiE9N2DRq2s3 5IRA== X-Gm-Message-State: APjAAAXOyu3qHi0Xlh2BpLYNt+YdgAflfMHwxn0slpfO4bMOHKEwRyYr bkZjbGMi9tw8vaNmd70S8ENCZOx7 X-Google-Smtp-Source: APXvYqyjJgJxl2bsTVyS5mdt+scThmW8zeZMRbydB+YW14YWueny/s/BYOB59gzDbnaC9xCdL0MpJw== X-Received: by 2002:adf:e3d0:: with SMTP id k16mr26041100wrm.241.1579015024288; Tue, 14 Jan 2020 07:17:04 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:03 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 2/6] fsnotify: pass dentry instead of inode for events possible on child Date: Tue, 14 Jan 2020 17:16:51 +0200 Message-Id: <20200114151655.29473-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Most events that can be reported to watching parent pass FSNOTIFY_EVENT_PATH as event data, except for FS_ARRTIB and FS_MODIFY as a result of truncate. Define a new data type to pass for event - FSNOTIFY_EVENT_DENTRY and use it to pass the dentry instead of it's ->d_inode for those events. Add a helper fsnotify_dentry(), similar to fsnotify_path() to report those events to child and parent. Soon, we are going to use the dentry data type to report events with name info in fanotify backend. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 ++ fs/notify/fsnotify.c | 4 ++-- include/linux/fsnotify.h | 16 ++++++++++------ include/linux/fsnotify_backend.h | 3 ++- kernel/audit_fsnotify.c | 5 ++++- kernel/audit_watch.c | 5 ++++- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 5778d1347b35..b4cd90afece1 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -271,6 +271,8 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, return to_tell; else if (data_type == FSNOTIFY_EVENT_INODE) return (struct inode *)data; + else if (data_type == FSNOTIFY_EVENT_DENTRY) + return d_inode(data); else if (data_type == FSNOTIFY_EVENT_PATH) return d_inode(((struct path *)data)->dentry); return NULL; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 46f225580009..13578372aee8 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -172,8 +172,8 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, &name.name, 0); else - ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, - &name.name, 0); + ret = fsnotify(p_inode, mask, dentry, + FSNOTIFY_EVENT_DENTRY, &name.name, 0); release_dentry_name_snapshot(&name); } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index a2d5d175d3c1..5746420bb121 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -41,9 +41,15 @@ static inline int fsnotify_parent(const struct path *path, } /* - * Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when - * an event is on a path. + * Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when + * an event is on a path/dentry. */ +static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) +{ + fsnotify_parent(NULL, dentry, mask); + fsnotify(d_inode(dentry), mask, dentry, FSNOTIFY_EVENT_DENTRY, NULL, 0); +} + static inline int fsnotify_path(struct inode *inode, const struct path *path, __u32 mask) { @@ -301,8 +307,7 @@ static inline void fsnotify_xattr(struct dentry *dentry) if (S_ISDIR(inode->i_mode)) mask |= FS_ISDIR; - fsnotify_parent(NULL, dentry, mask); - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_dentry(dentry, mask); } /* @@ -336,8 +341,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) if (S_ISDIR(inode->i_mode)) mask |= FS_ISDIR; - fsnotify_parent(NULL, dentry, mask); - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_dentry(dentry, mask); } } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index db3cabb4600e..cb47759b1ce9 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -212,10 +212,11 @@ struct fsnotify_group { }; }; -/* when calling fsnotify tell it if the data is a path or inode */ +/* when calling fsnotify tell it if the data is a path or inode or dentry */ #define FSNOTIFY_EVENT_NONE 0 #define FSNOTIFY_EVENT_PATH 1 #define FSNOTIFY_EVENT_INODE 2 +#define FSNOTIFY_EVENT_DENTRY 3 enum fsnotify_obj_type { FSNOTIFY_OBJ_TYPE_INODE, diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index f0d243318452..ec6d00fd11b4 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -168,7 +168,10 @@ static int audit_mark_handle_event(struct fsnotify_group *group, switch (data_type) { case (FSNOTIFY_EVENT_PATH): - inode = ((const struct path *)data)->dentry->d_inode; + inode = d_inode(((const struct path *)data)->dentry); + break; + case (FSNOTIFY_EVENT_DENTRY): + inode = d_inode(data); break; case (FSNOTIFY_EVENT_INODE): inode = (const struct inode *)data; diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index 4508d5e0cf69..85e007184677 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -482,7 +482,10 @@ static int audit_watch_handle_event(struct fsnotify_group *group, switch (data_type) { case (FSNOTIFY_EVENT_PATH): - inode = d_backing_inode(((const struct path *)data)->dentry); + inode = d_inode(((const struct path *)data)->dentry); + break; + case (FSNOTIFY_EVENT_DENTRY): + inode = d_inode(data); break; case (FSNOTIFY_EVENT_INODE): inode = (const struct inode *)data; From patchwork Tue Jan 14 15:16:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332479 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 1C05A1398 for ; Tue, 14 Jan 2020 15:17:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEBF224680 for ; Tue, 14 Jan 2020 15:17:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mlH+/4vo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729138AbgANPRI (ORCPT ); Tue, 14 Jan 2020 10:17:08 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46930 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgANPRI (ORCPT ); Tue, 14 Jan 2020 10:17:08 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so12497751wrl.13 for ; Tue, 14 Jan 2020 07:17:06 -0800 (PST) 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=LMdGC8h/b+0RUp5I4s67e3K7+OCIWfuzPBvZkge9vGs=; b=mlH+/4voyFo5BPKOtmGs5yk8e8YbvLhAxRotr+XFsKagwVsiUvxV+zucOvOhCmXvia UnVSK9Q2CzkBUwOxkpHTDObIXcKT8Cxy6nKwvZAc9ij6p7b9WSVSBXPGVWQi7DbdLWhR YteLZTTNqlymv9Z5vzMYPLeky038tMMOu2di88JUHk4V/MEZoyQfcfWP143icXfjy6dD 8sjYx/0qzxrSZ3EwRD6pEP0wHN1vDr1H/BO91Tkx7nCjY61Hi2U8zCK0bbmXXQqBM+C4 ewWzIj6ThLCNdHqV84f5ccsIESPEyfZ9o9/w9dZ0gQWc+PyBoJsubM5iebWXFIxkMYBx +DZA== 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=LMdGC8h/b+0RUp5I4s67e3K7+OCIWfuzPBvZkge9vGs=; b=BFY3txvUerPs7Tfwap4WaFqBgfEUzmj/yrmkUUnx9a4nVZEKOV23wgU/ueSgaHWjBI gKIPKjK+HDM5UaMPigZ2c4R79ohD/gAfS/PFWZHbXxWXQtLiFWQEJGp9FZzHg8Agr8HR nRbgYmznelSsq60kYgkhF2P0cqKiISvwauB8hygEbE0L0vuyZqXSK8B+QodpYTMd48tX Z0jXEqclLiWDvfBgSapZ/KASdHWmxppubW7t+iabEdipdi3bk9btufJvMyCAmcRReu7n lTLYWNB0GHIFt3Uf9OVk/FrNDz5VVVbmqiSaNaUjHRsK5oqg98fsr+q1Xg2PUkZ0M0hT ecFg== X-Gm-Message-State: APjAAAVVy4cWufiYdjOVJnzXbeBoYQPMfO2xiOpb7yzvlhKs6OCbDbvS WrMSMWNDJXEgHuYGbTftLb8= X-Google-Smtp-Source: APXvYqz5ZOVjGkDmyOV5pXPF0HQNZP8/yvx63hyGBgg/F6p+hCdZcwrRqs6URuI93TxdSvbGUH4ObQ== X-Received: by 2002:adf:ef49:: with SMTP id c9mr25214447wrp.292.1579015025307; Tue, 14 Jan 2020 07:17:05 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:04 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 3/6] fsnotify: simplify arguments passing to fsnotify_parent() Date: Tue, 14 Jan 2020 17:16:52 +0200 Message-Id: <20200114151655.29473-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of passing both dentry and path and having to figure out which one to use, use the data/data_type convention to simplify the code. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 21 ++++++++++----------- include/linux/fsnotify.h | 14 ++------------ include/linux/fsnotify_backend.h | 12 ++++++------ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 13578372aee8..a8b281569bbf 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -143,14 +143,18 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) } /* Notify this dentry's parent about a child's events. */ -int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask) +int fsnotify_parent(__u32 mask, const void *data, int data_type) { - struct dentry *parent; + struct dentry *parent, *dentry; struct inode *p_inode; int ret = 0; - if (!dentry) - dentry = path->dentry; + if (data_type == FSNOTIFY_EVENT_DENTRY) + dentry = (struct dentry *)data; + else if (data_type == FSNOTIFY_EVENT_PATH) + dentry = ((struct path *)data)->dentry; + else + return 0; if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) return 0; @@ -168,12 +172,7 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask mask |= FS_EVENT_ON_CHILD; take_dentry_name_snapshot(&name, dentry); - if (path) - ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, - &name.name, 0); - else - ret = fsnotify(p_inode, mask, dentry, - FSNOTIFY_EVENT_DENTRY, &name.name, 0); + ret = fsnotify(p_inode, mask, data, data_type, &name.name, 0); release_dentry_name_snapshot(&name); } @@ -181,7 +180,7 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask return ret; } -EXPORT_SYMBOL_GPL(__fsnotify_parent); +EXPORT_SYMBOL_GPL(fsnotify_parent); static int send_to_group(struct inode *to_tell, __u32 mask, const void *data, diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 5746420bb121..dfdc8a1a3c38 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -30,30 +30,20 @@ static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry, &dentry->d_name, 0); } -/* Notify this dentry's parent about a child's events. */ -static inline int fsnotify_parent(const struct path *path, - struct dentry *dentry, __u32 mask) -{ - if (!dentry) - dentry = path->dentry; - - return __fsnotify_parent(path, dentry, mask); -} - /* * Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when * an event is on a path/dentry. */ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) { - fsnotify_parent(NULL, dentry, mask); + fsnotify_parent(mask, dentry, FSNOTIFY_EVENT_DENTRY); fsnotify(d_inode(dentry), mask, dentry, FSNOTIFY_EVENT_DENTRY, NULL, 0); } static inline int fsnotify_path(struct inode *inode, const struct path *path, __u32 mask) { - int ret = fsnotify_parent(path, NULL, mask); + int ret = fsnotify_parent(mask, path, FSNOTIFY_EVENT_PATH); if (ret) return ret; diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index cb47759b1ce9..77edd866926f 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -351,9 +351,9 @@ struct fsnotify_mark { /* called from the vfs helpers */ /* main fsnotify call to send events */ -extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, - const struct qstr *name, u32 cookie); -extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask); +extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, + int data_type, const struct qstr *name, u32 cookie); +extern int fsnotify_parent(__u32 mask, const void *data, int data_type); extern void __fsnotify_inode_delete(struct inode *inode); extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); extern void fsnotify_sb_delete(struct super_block *sb); @@ -508,13 +508,13 @@ static inline void fsnotify_init_event(struct fsnotify_event *event, #else -static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, - const struct qstr *name, u32 cookie) +static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, + int data_type, const struct qstr *name, u32 cookie) { return 0; } -static inline int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask) +static inline int fsnotify_parent(__u32 mask, const void *data, int data_type) { return 0; } From patchwork Tue Jan 14 15:16:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332483 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 808F092A for ; Tue, 14 Jan 2020 15:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F6A92467D for ; Tue, 14 Jan 2020 15:17:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W523Srz1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729144AbgANPRJ (ORCPT ); Tue, 14 Jan 2020 10:17:09 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51376 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbgANPRI (ORCPT ); Tue, 14 Jan 2020 10:17:08 -0500 Received: by mail-wm1-f66.google.com with SMTP id d73so14219609wmd.1 for ; Tue, 14 Jan 2020 07:17:07 -0800 (PST) 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=xI6UsR2HtRTdQ7AnXLxpbvVM2BEy5RIvfWcGKDAXsbE=; b=W523Srz16ex4m6WIhfstZPV19MkeksaQB5qOxmHSV4QsdDSIQt4QDWFM/vk/Jm4PrM KMn8zkEwXyrgiU9+zh9yhiG9i0cIjZTqgzbFupQkfjEoxgyGUh8yJWWdQ12kXJYxJf9F EjRW4VoO72BAPFnUDYft8WuPq5Nw7BzCd05eBewwZZ9ecfTEnm+Ro1Nu0H6nBuSJymmc 9/26mOremHDvOAb0sOFLwHC0Lpz1hdB320JBs1ZF4NSyMNZQAP4han2+ok8F/TIdw1sS LKLa9+D/jN8PgK2njaT0BXPI/WEpfdt+dIfu3GkjrsQBPwevsblqaMcQdUWZi5YJRHAH cROw== 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=xI6UsR2HtRTdQ7AnXLxpbvVM2BEy5RIvfWcGKDAXsbE=; b=UlI0QahTuiiv04O81FI1k2w9bwSWqlQBtc4oj3U9395bRhLaF5GEz/th8jlBLBLQJB rqZ4uRWqik3fTmI+QUMeoefunRqJe2TZIgbCE2MTMjnoYGnGrVTX21lYQGor0h1+YSKi LhNdYQdyv3zV7CJZEFBcAcsitxtIbf75nT3yUbCAZyKpwApgobQNeVMtVgC6DCjuKBRx 4TnjXpHkUyJMMMpSnqUV1bGAS4NWWsWldTFREQB9vit6964XKF+m7D6YkksPI6neubJ4 194LPHIXZ5hkuDG+o8U38I2fzrDbxXazREE1DxxrF0p5ejT/HegNpXTShzOWPnwcHyBz SKLA== X-Gm-Message-State: APjAAAU5D97Ghul2PLIQkr8k49f25nuXLOOFrTekr/7PED0maVBMEAtD SINcuEdMRwQGrsHBjlesvaw= X-Google-Smtp-Source: APXvYqzyYuoSBBDDH/N77dbBgE8qME+Q5+2FnJEEwR5QsscwzTOvl9BVsVjALoxy8pKuM5qDf3dqjg== X-Received: by 2002:a1c:a745:: with SMTP id q66mr26617844wme.167.1579015026484; Tue, 14 Jan 2020 07:17:06 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:06 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 4/6] fsnotify: replace inode pointer with tag Date: Tue, 14 Jan 2020 17:16:53 +0200 Message-Id: <20200114151655.29473-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The event inode field is used only for comparison in queue merges and cannot be dereferenced after handle_event(), because it does not hold a refcount on the inode. Replace it with an abstract tag do to the same thing. We are going to set this tag for values other than inode pointer in fanotify. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/inotify/inotify_fsnotify.c | 2 +- include/linux/fsnotify_backend.h | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index b4cd90afece1..34454390e4b6 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -26,7 +26,7 @@ static bool should_merge(struct fsnotify_event *old_fsn, old = FANOTIFY_E(old_fsn); new = FANOTIFY_E(new_fsn); - if (old_fsn->inode != new_fsn->inode || old->pid != new->pid || + if (old_fsn->tag != new_fsn->tag || old->pid != new->pid || old->fh_type != new->fh_type || old->fh_len != new->fh_len) return false; diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index d510223d302c..cbaaec234fcd 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c @@ -39,7 +39,7 @@ static bool event_compare(struct fsnotify_event *old_fsn, if (old->mask & FS_IN_IGNORED) return false; if ((old->mask == new->mask) && - (old_fsn->inode == new_fsn->inode) && + (old_fsn->tag == new_fsn->tag) && (old->name_len == new->name_len) && (!old->name_len || !strcmp(old->name, new->name))) return true; diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 77edd866926f..caf8bbc1be08 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -132,8 +132,7 @@ struct fsnotify_ops { */ struct fsnotify_event { struct list_head list; - /* inode may ONLY be dereferenced during handle_event(). */ - struct inode *inode; /* either the inode the event happened to or its parent */ + unsigned long tag; /* identifier for queue merges */ }; /* @@ -499,11 +498,10 @@ extern void fsnotify_put_mark(struct fsnotify_mark *mark); extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info); extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info); -static inline void fsnotify_init_event(struct fsnotify_event *event, - struct inode *inode) +static inline void fsnotify_init_event(struct fsnotify_event *event, void *tag) { INIT_LIST_HEAD(&event->list); - event->inode = inode; + event->tag = (unsigned long)tag; } #else From patchwork Tue Jan 14 15:16:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332481 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 EDD871398 for ; Tue, 14 Jan 2020 15:17:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBD7224680 for ; Tue, 14 Jan 2020 15:17:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kViKAOA7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729139AbgANPRJ (ORCPT ); Tue, 14 Jan 2020 10:17:09 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38738 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729134AbgANPRI (ORCPT ); Tue, 14 Jan 2020 10:17:08 -0500 Received: by mail-wm1-f68.google.com with SMTP id u2so14143848wmc.3 for ; Tue, 14 Jan 2020 07:17:08 -0800 (PST) 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=ZT7fyZWv4Z8PX0V/HxqGVFS1bFMgoku/EGZ6kI9ggq8=; b=kViKAOA7Pb1bMjJ+IOv7KsWsCKY3uc+YhG9IcbRh6GFRSFimPCGRQtqO07ewcm812L qvRZ6ox9Sgt+gQxKEjnBZwjftX19jDpN/UMjVj/I43jiQAMBGGrT2Wys3L7V7hNuHyjb PIg9HvTORRIw3heuFEOXbF0XELZ2p6MiBZ2zwNiOzZBOpSzC6PehxG4UZxwGFmIIPjFr IWo4ObdVWo8RKM+pBFu48Zc4hZDB7p60AEnsdVxRJUq/yP07d7KV7kS45CnSJKMuGEbP kjpd+MH+QC+USpvzmbOWuvMHxFC4iQq9pPoBQlriBz2rdyEDlAdKBeDEjnDSSawqijeW ziSQ== 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=ZT7fyZWv4Z8PX0V/HxqGVFS1bFMgoku/EGZ6kI9ggq8=; b=aAN8LFB6+FUkazmjTcrZ1RGK+xPzbDht5Cbr93DkezlCIFaeyLeXkfpFfadGdciW0U t1+BUeV9nsjS5QYoTiZiN24OoikFe5RQ3RAPDrR7h4zFN5LMFXGmy6Ldp1gL/tCXEd7j hzRlrddNivjrRI9fKo5kn4PvYmN3tdoMvp1bhoqzFASgkC/JwefiipTQBm+oqaWV6Z9Z Gl024q8ywS6O6m9j44Cie7FqykL1UeFAxAFRNQMNPv18bk3fXAV8jBTOQkB22VwAAoyc aDqE7maRNeqadqatSooEodeJvoAnH8DYCRWP6zg518DQt6zP4idu6SmWF4de4t0hLfNt IPHg== X-Gm-Message-State: APjAAAUkPMJOhJJvMTpRfi0w8/PdmBJl1aCUHhAypMiRmnqhShEqcKbs Rx2EhQK/8gtkEcbXAYHuulYHPo/G X-Google-Smtp-Source: APXvYqzLuQpIeuT/eEat/mO22kYdxUXL482t5HPMSPsidhRHztzdI4N2h2Xs3vup01cm8/ZgB8EPVA== X-Received: by 2002:a7b:cf26:: with SMTP id m6mr26047196wmg.17.1579015027513; Tue, 14 Jan 2020 07:17:07 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:07 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 5/6] fanotify: merge duplicate events on parent and child Date: Tue, 14 Jan 2020 17:16:54 +0200 Message-Id: <20200114151655.29473-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org With inotify, when a watch is set on a directory and on its child, an event on the child is reported twice, once with wd of the parent watch and once with wd of the child watch without the filename. With fanotify, when a watch is set on a directory and on its child, an event on the child is reported twice, but it has the exact same information - either an open file descriptor of the child or an encoded fid of the child. The reason that the two identical events are not merged is because the tag used for merging events in the queue is the child inode in one event and parent inode in the other. For events with path or dentry data, use the dentry instead of inode as the tag for event merging, so that the event reported on parent will be merged with the event reported on the child. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 34454390e4b6..2ae82040f26f 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -265,17 +265,21 @@ static int fanotify_encode_fid(struct fanotify_event *event, * FS_CREATE reports the modified dir inode and not the created inode. */ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, - const void *data, int data_type) + const void *data, int data_type, + struct dentry **pdentry) { if (event_mask & ALL_FSNOTIFY_DIRENT_EVENTS) return to_tell; else if (data_type == FSNOTIFY_EVENT_INODE) return (struct inode *)data; else if (data_type == FSNOTIFY_EVENT_DENTRY) - return d_inode(data); + *pdentry = (struct dentry *)data; else if (data_type == FSNOTIFY_EVENT_PATH) - return d_inode(((struct path *)data)->dentry); - return NULL; + *pdentry = ((struct path *)data)->dentry; + else + return NULL; + + return d_inode(*pdentry); } struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, @@ -285,7 +289,9 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, { struct fanotify_event *event = NULL; gfp_t gfp = GFP_KERNEL_ACCOUNT; - struct inode *id = fanotify_fid_inode(inode, mask, data, data_type); + struct dentry *dentry = NULL; + struct inode *id = fanotify_fid_inode(inode, mask, data, data_type, + &dentry); /* * For queues with unlimited length lost events are not expected and @@ -316,7 +322,12 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, if (!event) goto out; init: __maybe_unused - fsnotify_init_event(&event->fse, inode); + /* + * Use the dentry instead of inode as tag for 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, (void *)dentry ?: inode); event->mask = mask; if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) event->pid = get_pid(task_pid(current)); From patchwork Tue Jan 14 15:16:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11332485 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 A6DB592A for ; Tue, 14 Jan 2020 15:17:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 868562467D for ; Tue, 14 Jan 2020 15:17:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eHPUoUdL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729148AbgANPRL (ORCPT ); Tue, 14 Jan 2020 10:17:11 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33783 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729140AbgANPRK (ORCPT ); Tue, 14 Jan 2020 10:17:10 -0500 Received: by mail-wm1-f67.google.com with SMTP id d139so2551261wmd.0 for ; Tue, 14 Jan 2020 07:17:09 -0800 (PST) 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=fWLq+NHJYf047UcKEJJJVBWiVqpObyKPnwSeuu3SPP0=; b=eHPUoUdLYZ/qOfXpMHvmR8LDBczxFafPl3agS7mVMz1nwJK1DJhL8eCpRiBrLe2uZM v9EeyVrV4lVTSmIhoy22E0nNlL22z34hBvLyZfK80qQVZgWAwVRMHGmpkDl88ndGSjjr +x1fLKPXdb+3RgfJj5kwo0O8cLN4C5ddXtv/Ijb/t/MmlLvarzZf5Sl1IUdDnPOGA8NJ fNf26zYWeHFVNJCRbGg9pcjwp/P+O6uLR72uAmc+/VTvZgUWfVrNM7ZRnkoZr0/thRoM sWR7qBb+zav5BH9IZF5GgpkxMdGZhla4mgFaFNCDLxziFdKgyE23cKQ9v+nFscXkHPNF 7Bvw== 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=fWLq+NHJYf047UcKEJJJVBWiVqpObyKPnwSeuu3SPP0=; b=X5RZqlQeY9eyI1HqwVxU9YObthUM2qUl53K1VkzEFZymiS36wADhvm3MZ/qr0TqkWR Z9pf7E2EIXdovmKJWBBr5VPyj/evaEGLNvQ7TQOtUM7D/rsGe/3eyJqzLm5HKsswYWUb 89a8kVaSiJiN89Ch81o0AZ++LNOopUWIfkUOAUrs8kbdr2Yr6oRffb6BIVdgZjaxmhaS cpCkStp/YvQvNxgzAzD+0KgbBKolXgM/2L8BUwqDMDxK4aYLdCIhlmQ57a0W5nKXdpzN JnF5Ug8vmm2mnX1YeyRG12PFLgqXTh/KGM6g31iT3u6RHkUVNnZSurVuD6eZtCwWi++E o1tA== X-Gm-Message-State: APjAAAXjmwMOxUKvu6FpaFbgyzADUICHujfgJsjYdQCSq5F2riX0XUNV mN/jjD7Y8EcpqPNWIGdGycFOTLax X-Google-Smtp-Source: APXvYqx3yqlvZ1+XcwJOkLmD+177ZJKerm6ZJpZkknk9ZGOhTXbuq0dwYqxDF0mFAlEfGg1xSd40Ag== X-Received: by 2002:a1c:730b:: with SMTP id d11mr28928418wmb.30.1579015028535; Tue, 14 Jan 2020 07:17:08 -0800 (PST) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id s19sm18276993wmj.33.2020.01.14.07.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 07:17:08 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 6/6] fanotify: fix merging marks masks with FAN_ONDIR Date: Tue, 14 Jan 2020 17:16:55 +0200 Message-Id: <20200114151655.29473-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200114151655.29473-1-amir73il@gmail.com> References: <20200114151655.29473-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Change the logic of FAN_ONDIR in two ways that are similar to the logic of FAN_EVENT_ON_CHILD, that was fixed in commit 54a307ba8d3c ("fanotify: fix logic of events on child"): 1. The flag is meaningless in ignore mask 2. The flag refers only to events in the mask of the mark where it is set This is what the fanotify_mark.2 man page says about FAN_ONDIR: "Without this flag, only events for files are created." It doesn't say anything about setting this flag in ignore mask to stop getting events on directories nor can I think of any setup where this capability would be useful. Currently, when marks masks are merged, the FAN_ONDIR flag set in one mark affects the events that are set in another mark's mask and this behavior causes unexpected results. For example, a user adds a mark on a directory with mask FAN_ATTRIB | FAN_ONDIR and a mount mark with mask FAN_OPEN (without FAN_ONDIR). An opendir() of that directory (which is inside that mount) generates a FAN_OPEN event even though neither of the marks requested to get open events on directories. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 2ae82040f26f..a98ee4340eaa 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -171,6 +171,13 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, if (!fsnotify_iter_should_report_type(iter_info, type)) continue; mark = iter_info->marks[type]; + /* + * If the event is on dir and this mark doesn't care about + * events on dir, don't send it! + */ + if (event_mask & FS_ISDIR && !(mark->mask & FS_ISDIR)) + continue; + /* * If the event is for a child and this mark doesn't care about * events on a child, don't send it! @@ -203,10 +210,6 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, user_mask &= ~FAN_ONDIR; } - if (event_mask & FS_ISDIR && - !(marks_mask & FS_ISDIR & ~marks_ignored_mask)) - return 0; - return test_mask & user_mask; }