From patchwork Wed Jul 8 11:11:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651363 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 9F60A739 for ; Wed, 8 Jul 2020 11:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8175720772 for ; Wed, 8 Jul 2020 11:12:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WaxYHoS1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728640AbgGHLMI (ORCPT ); Wed, 8 Jul 2020 07:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728466AbgGHLMI (ORCPT ); Wed, 8 Jul 2020 07:12:08 -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 3CF7AC08C5DC for ; Wed, 8 Jul 2020 04:12:08 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z15so37192343wrl.8 for ; Wed, 08 Jul 2020 04:12:08 -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; bh=oubne8wXWrj/bFxoGmKp7Zl07250gESHqIsh+1rMSPc=; b=WaxYHoS1h814+a8heXRRdVHAmgD7KB2BPU2JGpFcV3e3Owp15qkwFXP/kHaYbbP9zZ qAgHiCXn9adFArh5cmTt1rSAN0j3jSqwC6bNv9zGxKXnHXFGeBCaMSFLLqVG4Si91GSV rP5pM96oij3zMeJjxigCiPR63RDMbFDTkAswBTJm/e9clLcpS1OLwd3PJb+b4znvnbd+ bxEisXJ1N91w8vRfP8qAKOv/U327nrLji9uOBXrrbzlFxE7qi1S0p0jFnA9H+ClxZgJg d7L6FnUu2fxv4xf55f/usjPFun2S9SMRfIQMlTztRkKxTkVCFzp2lNBZHCiQSEl14fYH XtzA== 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; bh=oubne8wXWrj/bFxoGmKp7Zl07250gESHqIsh+1rMSPc=; b=aiQghzNvTfJkNbVbPMBmoEzG/dTjwVK8cSPer40xOtMH32kkG20Tv0FlLvjuWYA1ne 2ApaADv88K0GOX3HpHwlz4/DvlUE484emLY8dCv/OQrKHtXV+0808mPIGmz2U7HYW4WP Pklt72qHI0MBKFeJGarpM0DnqZ/iZjRdSGb3eg/gz3/7iSKaY0VgExqgVjQYxBP4zie5 bNNBlevp5wBEe+FpmAD0Djj7IJ8mOcaSan6HwpxE3QZeJoPNHG9DNcoU82ECI1mNDk50 6zlLtoLISlXswkqhmijnMk9gp/kfiHOuz/kbYuTNq9YVwb/pzQBxtbIGOMWhUh5GVZls AJWA== X-Gm-Message-State: AOAM531f/za84bcLrzJBHg9D2sGGPS+UP4FsPIQYdKAUuEiYJ4bv8X8o EWfAS3QyoRK8UnZ1VDLEhEeEvLcA X-Google-Smtp-Source: ABdhPJydbZAuJh/Yjsf0V4xDSyj1oGg6xBUFZ9RNBXfijQUEN600RINqh/OSP3W32ZvKojRpQIDN+A== X-Received: by 2002:a5d:4d8b:: with SMTP id b11mr58431508wru.341.1594206726890; Wed, 08 Jul 2020 04:12:06 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:06 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, Mel Gorman Subject: [PATCH v3 01/20] fsnotify: Rearrange fast path to minimise overhead when there is no watcher Date: Wed, 8 Jul 2020 14:11:36 +0300 Message-Id: <20200708111156.24659-1-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Mel Gorman The fsnotify paths are trivial to hit even when there are no watchers and they are surprisingly expensive. For example, every successful vfs_write() hits fsnotify_modify which calls both fsnotify_parent and fsnotify unless FMODE_NONOTIFY is set which is an internal flag invisible to userspace. As it stands, fsnotify_parent is a guaranteed functional call even if there are no watchers and fsnotify() does a substantial amount of unnecessary work before it checks if there are any watchers. A perf profile showed that applying mnt->mnt_fsnotify_mask in fnotify() was almost half of the total samples taken in that function during a test. This patch rearranges the fast paths to reduce the amount of work done when there are no watchers. The test motivating this was "perf bench sched messaging --pipe". Despite the fact the pipes are anonymous, fsnotify is still called a lot and the overhead is noticeable even though it's completely pointless. It's likely the overhead is negligible for real IO so this is an extreme example. This is a comparison of hackbench using processes and pipes on a 1-socket machine with 8 CPU threads without fanotify watchers. 5.7.0 5.7.0 vanilla fastfsnotify-v1r1 Amean 1 0.4837 ( 0.00%) 0.4630 * 4.27%* Amean 3 1.5447 ( 0.00%) 1.4557 ( 5.76%) Amean 5 2.6037 ( 0.00%) 2.4363 ( 6.43%) Amean 7 3.5987 ( 0.00%) 3.4757 ( 3.42%) Amean 12 5.8267 ( 0.00%) 5.6983 ( 2.20%) Amean 18 8.4400 ( 0.00%) 8.1327 ( 3.64%) Amean 24 11.0187 ( 0.00%) 10.0290 * 8.98%* Amean 30 13.1013 ( 0.00%) 12.8510 ( 1.91%) Amean 32 13.9190 ( 0.00%) 13.2410 ( 4.87%) 5.7.0 5.7.0 vanilla fastfsnotify-v1r1 Duration User 157.05 152.79 Duration System 1279.98 1219.32 Duration Elapsed 182.81 174.52 This is showing that the latencies are improved by roughly 2-9%. The variability is not shown but some of these results are within the noise as this workload heavily overloads the machine. That said, the system CPU usage is reduced by quite a bit so it makes sense to avoid the overhead even if it is a bit tricky to detect at times. A perf profile of just 1 group of tasks showed that 5.14% of samples taken were in either fsnotify() or fsnotify_parent(). With the patch, 2.8% of samples were in fsnotify, mostly function entry and the initial check for watchers. The check for watchers is complicated enough that inlining it may be controversial. [Amir] Slightly simplify with mnt_or_sb_mask => marks_mask Signed-off-by: Mel Gorman Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 27 +++++++++++++++------------ include/linux/fsnotify.h | 10 ++++++++++ include/linux/fsnotify_backend.h | 4 ++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 72d332ce8e12..d59a58d10b84 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -143,7 +143,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) } /* Notify this dentry's parent about a child's events. */ -int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, +int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type) { struct dentry *parent; @@ -174,7 +174,7 @@ int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, 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, @@ -315,17 +315,11 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, struct fsnotify_iter_info iter_info = {}; struct super_block *sb = to_tell->i_sb; struct mount *mnt = NULL; - __u32 mnt_or_sb_mask = sb->s_fsnotify_mask; int ret = 0; - __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); + __u32 test_mask, marks_mask; - if (path) { + if (path) 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 @@ -337,13 +331,22 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, if (!to_tell->i_fsnotify_marks && !sb->s_fsnotify_marks && (!mnt || !mnt->mnt_fsnotify_marks)) return 0; + + /* An event "on child" is not intended for a mount/sb mark */ + marks_mask = to_tell->i_fsnotify_mask; + if (!(mask & FS_EVENT_ON_CHILD)) { + marks_mask |= sb->s_fsnotify_mask; + if (mnt) + marks_mask |= mnt->mnt_fsnotify_mask; + } + /* * if this is a modify event we may need to clear the ignored masks * otherwise return if neither the inode nor the vfsmount/sb care about * this type of event. */ - if (!(mask & FS_MODIFY) && - !(test_mask & (to_tell->i_fsnotify_mask | mnt_or_sb_mask))) + test_mask = (mask & ALL_FSNOTIFY_EVENTS); + if (!(mask & FS_MODIFY) && !(test_mask & marks_mask)) return 0; iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 5ab28f6c7d26..508f6bb0b06b 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -44,6 +44,16 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0); } +/* Notify this dentry's parent about a child's events. */ +static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, + const void *data, int data_type) +{ + if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) + return 0; + + return __fsnotify_parent(dentry, mask, data, data_type); +} + /* * Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when * an event is on a file/dentry. diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index f0c506405b54..1626fa7d10ff 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -379,7 +379,7 @@ struct fsnotify_mark { /* main fsnotify call to send events */ 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(struct dentry *dentry, __u32 mask, const void *data, +extern int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type); extern void __fsnotify_inode_delete(struct inode *inode); extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); @@ -541,7 +541,7 @@ static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, return 0; } -static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, +static inline int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type) { return 0; From patchwork Wed Jul 8 11:11:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651365 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 E4374739 for ; Wed, 8 Jul 2020 11:12:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C760D20772 for ; Wed, 8 Jul 2020 11:12:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m2NcTcbB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728658AbgGHLML (ORCPT ); Wed, 8 Jul 2020 07:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgGHLMK (ORCPT ); Wed, 8 Jul 2020 07:12:10 -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 6712BC08C5DC for ; Wed, 8 Jul 2020 04:12:10 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id g10so3744050wmc.1 for ; Wed, 08 Jul 2020 04:12:10 -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=33Xisl4lMhvn/WaDKdXc9pHfauIoD/BUq0VCz7uTm/s=; b=m2NcTcbBYi7vrBWHSDzG0bzZ7d9onedv+8kzDZEPbrKXyADmju8bSiQZ4xY4YD5os+ 9JTZUpLvY1jtvHXnrNJxgVPJw6Q9E9xujWjMnGi2KbY2KFdpe74tE5VEq96AF7PVJkA9 yzY6NIWxgyz8ch/pbiXNIr0/Vc7w5wPXzUQSZuTakVprPcCNUeJjwhEqc5ISEXR9huxc zDpuYJ5Z9wsfmjpPmQYjVxRE4tHZKuWE9jHhLzDRrPv6pWUOZyIewzZgNCqsr21EPQrp kon31Te02aJhmFNH47pN9Z/GiLmC2fOX1nq6fYR+T8q+jhfbRar4pwy0QDWvcA/CVUbc HPgw== 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=33Xisl4lMhvn/WaDKdXc9pHfauIoD/BUq0VCz7uTm/s=; b=IEbIx+RQvpV7+pFEl6ITLO+85I3xkXB+UiZLY8u1v4H2R6hpdCLFkKPOO1XZ1GCjej RKLbCcxXujzRoInIAlwTQQnUwGP5MQ3pqZDc+icwdgHfnXdUVq/BISfU21vYsLBxBWwC td3Kfp/rXPZji/E+WiOeRre7IgjwETm970THnFFIWLUAPLr28N8H8d482ZrnS/bKzeRI p9jxeVvek2bfRncWBRYIXNr+1BMaVTYc9KQlY/mRQ5rG1J8THvXkJsjvqTx9bVf7X9/x qHcQi9iWbo6bNsHJSxEdIJXycVYztCfIc2QGy/sj+/f+JP9iWkRGPQlqu0EJu/7zZy9t DVXg== X-Gm-Message-State: AOAM530TOrKQTFg1YiD1g5QC0uS5ql9ie/Qf6B7oGyaTh5UuEiDsFd4n SdGrancvRo4swFwzrVygCaA= X-Google-Smtp-Source: ABdhPJzIJdUgxmE+R1EVcAtQ0BCwuBWmK8h9g6ltfa352KfKEUhkI1l8dGbPx3z0wfcOq+oWLlyNxg== X-Received: by 2002:a7b:cb92:: with SMTP id m18mr6953059wmi.94.1594206728380; Wed, 08 Jul 2020 04:12:08 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:07 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 02/20] fsnotify: fold fsnotify() call into fsnotify_parent() Date: Wed, 8 Jul 2020 14:11:37 +0300 Message-Id: <20200708111156.24659-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org All (two) callers of fsnotify_parent() also call fsnotify() to notify the child inode. Move the second fsnotify() call into fsnotify_parent(). This will allow more flexibility in making decisions about which of the two event falvors should be sent. Using 'goto notify_child' in the inline helper seems a bit strange, but it mimics the code in __fsnotify_parent() for clarity and the goto pattern will become less strage after following patches are applied. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 27 ++++++++++++++++++--------- include/linux/fsnotify.h | 33 +++++++++++++-------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index d59a58d10b84..30628a72ca01 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -142,16 +142,20 @@ 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 with child name info + * if parent is watching. + * Notify also the child without name info if child inode is watching. + */ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, - int data_type) + int data_type) { struct dentry *parent; struct inode *p_inode; int ret = 0; if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) - return 0; + goto notify_child; parent = dget_parent(dentry); p_inode = parent->d_inode; @@ -161,18 +165,23 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, } else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) { struct name_snapshot name; - /* we are notifying a parent so come up with the new mask which - * specifies these are events which came from a child. */ - mask |= FS_EVENT_ON_CHILD; - + /* + * We are notifying a parent, so set a flag in mask to inform + * backend that event has information about a child entry. + */ take_dentry_name_snapshot(&name, dentry); - ret = fsnotify(p_inode, mask, data, data_type, &name.name, 0); + ret = fsnotify(p_inode, mask | FS_EVENT_ON_CHILD, data, + data_type, &name.name, 0); release_dentry_name_snapshot(&name); } dput(parent); - return ret; + if (ret) + return ret; + +notify_child: + return fsnotify(d_inode(dentry), mask, data, data_type, NULL, 0); } EXPORT_SYMBOL_GPL(__fsnotify_parent); diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 508f6bb0b06b..316c9b820517 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -48,44 +48,37 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type) { + struct inode *inode = d_inode(dentry); + + if (S_ISDIR(inode->i_mode)) + mask |= FS_ISDIR; + if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) - return 0; + goto notify_child; return __fsnotify_parent(dentry, mask, data, data_type); + +notify_child: + return fsnotify(inode, mask, data, data_type, NULL, 0); } /* - * Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when - * an event is on a file/dentry. + * Simple wrappers to consolidate calls to fsnotify_parent() when an event + * is on a file/dentry. */ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) { - struct inode *inode = d_inode(dentry); - - if (S_ISDIR(inode->i_mode)) - mask |= FS_ISDIR; - - fsnotify_parent(dentry, mask, inode, FSNOTIFY_EVENT_INODE); - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE); } static inline int fsnotify_file(struct file *file, __u32 mask) { const struct path *path = &file->f_path; - struct inode *inode = file_inode(file); - int ret; if (file->f_mode & FMODE_NONOTIFY) return 0; - if (S_ISDIR(inode->i_mode)) - mask |= FS_ISDIR; - - ret = fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); - if (ret) - return ret; - - return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); + return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); } /* Simple call site for access decisions */ From patchwork Wed Jul 8 11:11:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651367 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 6773614E3 for ; Wed, 8 Jul 2020 11:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E77420772 for ; Wed, 8 Jul 2020 11:12:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dcd6SfD1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728700AbgGHLML (ORCPT ); Wed, 8 Jul 2020 07:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728466AbgGHLML (ORCPT ); Wed, 8 Jul 2020 07:12:11 -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 C8FA0C08E6DC for ; Wed, 8 Jul 2020 04:12:10 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id 22so2501142wmg.1 for ; Wed, 08 Jul 2020 04:12:10 -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=IUb/hJFbGNPx/GA4uExNVhANvviQpWzogW7D2fGl5nk=; b=dcd6SfD1Q7sSM50XntDWnsdFE5pM/7B7JVx0fVEiIkel2NAqrI7uNRffge6CXY0DKS +zwDyTGv02ejUHjxNJGl19902UooC9L366E9RKKzEx/OkO8bpkve1vGjtf1kLwCK/9tO 1at66FMMTuLCdcLDQDpJ0zc+fyRwlEuruXKuqhBBlM4551ciHXAw/fxp6ZUI2YaClcCq 7wayEMarLNq3/O6EXtsABGFxp0jrZ01/FCp0SxAQXTldp2rn7ksM3X4lZVU9E+6LEcDB qgjumSVxDDUTkoH5MhT04MqSkMUjoxXEK3kK12yM6Q8F9R1nGRwWOe2sOXatl+ZseDlO ItkA== 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=IUb/hJFbGNPx/GA4uExNVhANvviQpWzogW7D2fGl5nk=; b=tk/0G2AFTLdbmFjQ19dhfWuEg4heeUKpYRvXUsnxBxZUcj0gTg2MOcwig/gjnLX7m5 kqj+8WQN+as/BBnQgq6JFhg7TlQRTq0hHy5ZfrxZ43hat3Gxt82CdUWITDgjgcO9AWHM ob8CSCL8yNwjFh29Gf1D+DU20WqnY1OaRoNsZt0rSdEDU94xjW9eeM1KQXSn3bY+32P9 WEWEthdWlFdPj/fUUUSaHVawVJmC+2fUQt9vp+fnLpClyhkqCZSXeqvPvdRV77ZFcQJl OB5qc5/zAf/mKrOOfveTcQTtzdsb8rlWrScNYtrcnBFPDbN4tR/o/sS9OCZlIgthcmpI QLIg== X-Gm-Message-State: AOAM532kLPwjNtDLnrjdjfZjnQhLNiwlIxe6RaXcAyvJf82Ppr3SJzWr KkCrUempEBiSIfys/ax7RdoSZuUF X-Google-Smtp-Source: ABdhPJyGb8Y+XWfM1/vsnb76ZixdtQVUh1LqbZ7mc+C7XKZ94HG1NJlsd+dTQxom8d22xOhg5BjegA== X-Received: by 2002:a7b:c7c2:: with SMTP id z2mr8744221wmk.39.1594206729619; Wed, 08 Jul 2020 04:12:09 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:09 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 03/20] fsnotify: return non const from fsnotify_data_inode() Date: Wed, 8 Jul 2020 14:11:38 +0300 Message-Id: <20200708111156.24659-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Return non const inode pointer from fsnotify_data_inode(). None of the fsnotify hooks pass const inode pointer as data and callers often need to cast to a non const pointer. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 +- include/linux/fsnotify_backend.h | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 85eda539b35f..d9fc83dd994a 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -341,7 +341,7 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, if (event_mask & ALL_FSNOTIFY_DIRENT_EVENTS) return to_tell; - return (struct inode *)fsnotify_data_inode(data, data_type); + return fsnotify_data_inode(data, data_type); } struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 1626fa7d10ff..97300f3b8ff0 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -220,12 +220,11 @@ enum fsnotify_data_type { FSNOTIFY_EVENT_INODE, }; -static inline const struct inode *fsnotify_data_inode(const void *data, - int data_type) +static inline struct inode *fsnotify_data_inode(const void *data, int data_type) { switch (data_type) { case FSNOTIFY_EVENT_INODE: - return data; + return (struct inode *)data; case FSNOTIFY_EVENT_PATH: return d_inode(((const struct path *)data)->dentry); default: From patchwork Wed Jul 8 11:11:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651369 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 D541F739 for ; Wed, 8 Jul 2020 11:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B141D20771 for ; Wed, 8 Jul 2020 11:12:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E6/03ats" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728735AbgGHLMO (ORCPT ); Wed, 8 Jul 2020 07:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728466AbgGHLMM (ORCPT ); Wed, 8 Jul 2020 07:12:12 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 181DAC08C5DC for ; Wed, 8 Jul 2020 04:12:12 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id 22so2501255wmg.1 for ; Wed, 08 Jul 2020 04:12:12 -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=E8Ml8tqMdTEJp/V9Pm/cWxKNJj9YiDr2BArYDfp0AdY=; b=E6/03atsFQn9XHs/fks6sZMOhg8S4ljEE4AeJXwAaa09a5/R6huaA+IC61pUJs6Cou eJONNJKv5J4295qq8D/73ZPLzpGNoST6sDB7W2me/Ac/JlN9dmsg3RP9k5gy7yjQvFhk Hmluu7NAXvKU+5oYZGCbpmdarE3hTkU9Q0CfXIC7zhQtFJinNDIdjiYb7GKB5c9SJDAA AQtwqCks5r/agfkbSv7mFAfBPqbw35BLpaCwLDvwwpsltTeXZJ2l6yEwATf/isQe8Swv Bma4uulIyneEPG+c4qYe6rlFI/mAIpgxP/1fZs/IQoRhgH/UzbUIXEwOlskjL+83Vzgo Erqw== 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=E8Ml8tqMdTEJp/V9Pm/cWxKNJj9YiDr2BArYDfp0AdY=; b=nRpaekPSOFBe8lYyIyUc1rF0hFTyOqjvTzpSkandk+L6AMThWXAVUMFmiSjtMWHqAB PN9pzTCAZfV7ic29i+gtw6uQz4UHb6MXSwz9ZYO4If800kVYuyuLKMZr4CA+kGKO+uIK Jc3Xj5+aS3KsfZV7qUkCNz/OKXEHIilNLnuEtRjKFudSsBJKBv0eXP5x1yUdrXtbbFbq nHt9Koe0aO13mmmn/SExvHIbtnEYoa6jA6fdUau9Embq65ktMWEYulWn4V4nHY5WWdYf sy4rF00I03FxKgcFXXLvshZEG9+wb/nCkGnjro/2sbcgFlsTVO9NyxUqV2lb47VTYh74 qZTw== X-Gm-Message-State: AOAM5312G++Ilth0nh4FlDZCT3rFZWBSXOA1XZ1Cpfjeq2BTy/tXxLjy La1FXFM06D9UlFp0Uh9qo6C0skJk X-Google-Smtp-Source: ABdhPJxIhwLq74qHtcs4fme9VfoWXjShyhRldi/OHydxOA4VBAsYjKkCcmApo/MK9UIG+P6VptDcSA== X-Received: by 2002:a1c:6a13:: with SMTP id f19mr2384021wmc.106.1594206730892; Wed, 08 Jul 2020 04:12:10 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:10 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 04/20] nfsd: use fsnotify_data_inode() to get the unlinked inode Date: Wed, 8 Jul 2020 14:11:39 +0300 Message-Id: <20200708111156.24659-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The inode argument to handle_event() is about to become obsolete. Signed-off-by: Amir Goldstein --- fs/nfsd/filecache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 82198d747c4c..ace8e5c30952 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -599,11 +599,13 @@ static struct notifier_block nfsd_file_lease_notifier = { static int nfsd_file_fsnotify_handle_event(struct fsnotify_group *group, - struct inode *inode, + struct inode *to_tell, u32 mask, const void *data, int data_type, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { + struct inode *inode = fsnotify_data_inode(data, data_type); + trace_nfsd_file_fsnotify_handle_event(inode, mask); /* Should be no marks on non-regular files */ From patchwork Wed Jul 8 11:11:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651371 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 A7D2613B4 for ; Wed, 8 Jul 2020 11:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9181220772 for ; Wed, 8 Jul 2020 11:12:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X1Au66AB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728743AbgGHLMO (ORCPT ); Wed, 8 Jul 2020 07:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMO (ORCPT ); Wed, 8 Jul 2020 07:12:14 -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 B49A7C08E6DC for ; Wed, 8 Jul 2020 04:12:13 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id a6so3748046wmm.0 for ; Wed, 08 Jul 2020 04:12:13 -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=wW7i379j65GNEXl3sU/RlLG0qLaHJvRj9OVSBvvQeeU=; b=X1Au66ABqmpUohFrlSKCmUWwcalFZz4pmEbXM3nRhW3QpfUQYkpdqU0NIP/R8iQ1UA eY/9JYWYqriWn+Xjdiyz1g+yLh3wfj0uoBJVOngcLf5PsI9GVvqTaIgV6YKj8Kr3zFi1 OsZlvcqdX2K3gKVQ3sRAqrGQ3cwjcTMnl8ByPiO/IrDV/RiVUd0u0i14SiMj67Xhg7aP ixx/ZekwLBdYwekleUt0XniX14/JEZbngBlzC/jtyXFCM3yuVoVG+wh44Sys5DS7s2fz ubZesDXjo58lj5O9M/BBBj1WeQDdErdyaw70S4Fl37jTM+GVrRYzlSs7QZOEPn1lSlfh kVMg== 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=wW7i379j65GNEXl3sU/RlLG0qLaHJvRj9OVSBvvQeeU=; b=KyOkLlnq9mqRbn1X0h8HqgTLAdZaAQkJMMPB6+NyXpTX1ZUO7Bx280AcaTTivICdRN wRKURB40Mf4CujvoibiRLo/8Y4S+hvg4xjWXA77vxzk/3PSs3PeMA64IbpmFLA7MJT8W g/riwvX+AElgQwOsWNF7qHwbrRA6M5Qtm2m8nTLWApk472UgizQHAutsEUcI0IZlRmps iwFT58Kj0rHwVAd3zARb2w1FWKJuYD1tGX7cN+d5gTUIs9jsoOEkrUaeJPJLUNgnrjCv 8CbBSQjyAYlx/F5gSnf86fxzrU4NJ07sR11XXS9uc4GjbVIP95XTv6hZRKJxmWrN64S9 BDHg== X-Gm-Message-State: AOAM532xfVrevkahCkTfD0g+dKlEPUXH5NDr9FZHJYsCNlJuc4ohvZ8x xLGXtn/k8i589y90LzywUTlJERF1 X-Google-Smtp-Source: ABdhPJy0Bxg63fVMYZgZho6dI36/5Zwr8JOzU9nRg5lVqozfDPSXQzjO1dmD4qZeDo0kSFGRtIZHpQ== X-Received: by 2002:a1c:48:: with SMTP id 69mr9186376wma.32.1594206732455; Wed, 08 Jul 2020 04:12:12 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:11 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 05/20] kernfs: do not call fsnotify() with name without a parent Date: Wed, 8 Jul 2020 14:11:40 +0300 Message-Id: <20200708111156.24659-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When creating an FS_MODIFY event on inode itself (not on parent) the file_name argument should be NULL. The change to send a non NULL name to inode itself was done on purpuse as part of another commit, as Tejun writes: "...While at it, supply the target file name to fsnotify() from kernfs_node->name.". But this is wrong practice and inconsistent with inotify behavior when watching a single file. When a child is being watched (as opposed to the parent directory) the inotify event should contain the watch descriptor, but not the file name. Fixes: df6a58c5c5aa ("kernfs: don't depend on d_find_any_alias()...") Acked-by: Tejun Heo Acked-by: Greg Kroah-Hartman Signed-off-by: Amir Goldstein --- fs/kernfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 06b342d8462b..e23b3f62483c 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -912,7 +912,7 @@ static void kernfs_notify_workfn(struct work_struct *work) } fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE, - &name, 0); + NULL, 0); iput(inode); } From patchwork Wed Jul 8 11:11:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651373 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 0D806739 for ; Wed, 8 Jul 2020 11:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA4C820772 for ; Wed, 8 Jul 2020 11:12:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eYXJgcO/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728763AbgGHLMT (ORCPT ); Wed, 8 Jul 2020 07:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728752AbgGHLMP (ORCPT ); Wed, 8 Jul 2020 07:12:15 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07E1CC08E6DC for ; Wed, 8 Jul 2020 04:12:15 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id o2so2525439wmh.2 for ; Wed, 08 Jul 2020 04:12:14 -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=8UVubkuXhicUmFZ2Y1+zmG91pHnTICwuP72MUM8XTwU=; b=eYXJgcO/Jn/oZHiz59nYYCBwYMcXg7EF2Gw7rPkn/ukoezL6yCgFB2r+ABufiPoBjr Rk9fD0nYMQ9zCMlue3XM/ZPmXcjgOXj1dQ1W0iHZaRW7Uow9L3vShIFkBptnA0NtLXL4 fnTWmb851znmmAvjObpqF1wY8H4dWJmPALaHaPfJiTBENHRDrKw6WCzgpKkQVNsXOK8K 6uvnT8PNS1jGqZzwwFILNo81Z783MNw+34+wBBK0MRamkMITuiFcoVyfV1x2B1Z6YYvr iPFWXfApg0my2rbNQTR2G+dArfIYyTK37mAxpRd7xHFX7HNepxoNfP02FNe6Rge8lsn5 hkuQ== 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=8UVubkuXhicUmFZ2Y1+zmG91pHnTICwuP72MUM8XTwU=; b=kX4XwQBF7KH3AtihObEbPL/VVfCYN4c39+42e7XM1d4gouQwlv4dxoC9GNxaRmSQKY RlkyrNT7b26kgvlZesGK753vb66mE2fQgmv1fDykSpVv+pp0oVb1UmmXOQufooQY5dwd 3XmTEWsKRQ3AdxeTpIFGsS93Ihf2kVQ6adfvcdhSaCngjmLqqxMkDM6ODRNSy4ubrIvj uNYp+2YEVUcAS9X6G/hHFhqEHDzbj/i/CXi5rwWUp+GW26v773BfT4Q3K+O3Pr7/hZ5B UO5eunqQ7DfW81i1E7xWut+Ms4ay2H7pTblEX+zRUCMPvl2Nqo/t/hFmaEcpPx9SL0px XyUw== X-Gm-Message-State: AOAM531Qx+hmUW9AsDgeYjKKaOqd0DKR4+KUEB07uGCAnufuN8lD9YXo KV7Fw4Kmg9UU3FAWwbTHUt/fp5Lm X-Google-Smtp-Source: ABdhPJzkXrOeVhZ0betd6yHRQKa8G3BYgrLMMvqpN23LOiMYGSaNRZJzVO/f8T/Fn1D6UgM4rUKDJg== X-Received: by 2002:a7b:ca4c:: with SMTP id m12mr8914262wml.33.1594206733779; Wed, 08 Jul 2020 04:12:13 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:13 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 06/20] inotify: do not use objectid when comparing events Date: Wed, 8 Jul 2020 14:11:41 +0300 Message-Id: <20200708111156.24659-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org inotify's event->wd is the object identifier. Compare that instead of the common fsnotidy event objectid, so we can get rid of the objectid field later. Signed-off-by: Amir Goldstein --- fs/notify/inotify/inotify_fsnotify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index 2ebc89047153..9b481460a2dc 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->objectid == new_fsn->objectid) && + (old->wd == new->wd) && (old->name_len == new->name_len) && (!old->name_len || !strcmp(old->name, new->name))) return true; @@ -116,7 +116,7 @@ int inotify_handle_event(struct fsnotify_group *group, mask &= ~IN_ISDIR; fsn_event = &event->fse; - fsnotify_init_event(fsn_event, (unsigned long)inode); + fsnotify_init_event(fsn_event, 0); event->mask = mask; event->wd = i_mark->wd; event->sync_cookie = cookie; From patchwork Wed Jul 8 11:11:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651375 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 A2B5514E3 for ; Wed, 8 Jul 2020 11:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 843CC20771 for ; Wed, 8 Jul 2020 11:12:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KFe1hz6c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728765AbgGHLMT (ORCPT ); Wed, 8 Jul 2020 07:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728711AbgGHLMR (ORCPT ); Wed, 8 Jul 2020 07:12:17 -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 D04A2C08E763 for ; Wed, 8 Jul 2020 04:12:16 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id g75so2473004wme.5 for ; Wed, 08 Jul 2020 04:12:16 -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=hP42MA+PQNeh5/lNY5nfswLPCWPrDLJB57T2z7yHDZ4=; b=KFe1hz6c3FFOdh6X61XaSE2EWW7OTbDUAUOZEddltsmgSX3tUrzzZRxzb7YAW8q+f3 mtjEPBVC7tH+vUPrGZvx7wOpR8RPrApLPn8cpdUhIihxAfVqmZLctbOzx7b2xmghHCPU RVU5JkD4aj/AdgbnHjZjnGvPxhaBS/9RZNCUXEGnT6ohJcXDTr/vZYT/eOVTh081HkhY 8l/FPHPQcdzytqbAGywq08xOg8fy+5aQ7m1gD9oRPDAg33/Z4rePHaMfHWJbo8ABTfbV 5TuO+ltRlK9QWcBOWjj6BGskdFWBNVYHr6DW5U2vxdqxkjce48C7u4SL2sPLvIHv4fjG GE7A== 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=hP42MA+PQNeh5/lNY5nfswLPCWPrDLJB57T2z7yHDZ4=; b=UvCWBKAzInlfLWJU7PCN1ce5NMoEr5gAuKyyJkiN3fgZItI56wpcKcjTHmbOh5oYEm slauIAYVA3p1TuNvy1R0edXByjCttRleFfST5zOUZSNBQ35uylNcvzO+VkYbASx5XvzH cSkkcKE7tyGPFm/xnTUzhv3UUFEyzBvxBxrWLlI0VYcWnzpWJ8PlgGIxrb780JOYjkqi A/as0mvlpMSGh1r3g+erjgggMomTsnMgfNCCIqzBvXUmfJrxKGtdQN1E7ku/9eQxiR3+ jJNoBEqZtqJCfhjJ0InCK5rxX9qp8e2DEwBUyKNgD5mucOCdaKLtNQZqS7Z3GkQuF4ho inAA== X-Gm-Message-State: AOAM531h81YO9e08/R6Vc2A2+Nrwjd1EOV/yNtTKEIN8UNgJliDJAM2j 0il6q1dl7yySBTEbvfnrHFTmeasi X-Google-Smtp-Source: ABdhPJybe7Yox6/2mvtinBS6ruHH3afhMwzBGRS1Coo9FjtjbGdtLpcgQesyvZjbCWY5hOJ/I6+Wkg== X-Received: by 2002:a7b:c44d:: with SMTP id l13mr9196993wmi.66.1594206735620; Wed, 08 Jul 2020 04:12:15 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:14 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 07/20] fanotify: create overflow event type Date: Wed, 8 Jul 2020 14:11:42 +0300 Message-Id: <20200708111156.24659-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-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 d9fc83dd994a..921ff05e1877 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -344,11 +344,11 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, return 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; @@ -426,8 +426,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 @@ -443,15 +442,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(); @@ -640,6 +632,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 8ce7ccfc4b0d..1b2a3bbe6008 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 63b5dffdca9e..8f3c70873598 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -831,13 +831,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); @@ -892,13 +905,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 Wed Jul 8 11:11:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651377 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 4F24B13B4 for ; Wed, 8 Jul 2020 11:12:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 314A820772 for ; Wed, 8 Jul 2020 11:12:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CJlOsYR8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728770AbgGHLMU (ORCPT ); Wed, 8 Jul 2020 07:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMT (ORCPT ); Wed, 8 Jul 2020 07:12:19 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28F1C08C5DC for ; Wed, 8 Jul 2020 04:12:18 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id r12so48404195wrj.13 for ; Wed, 08 Jul 2020 04:12:18 -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=l/AE762kcZ5+fefPuuyQiLmzvis/P6HnGtNK2oQ0l8U=; b=CJlOsYR84u7tMj2e63uxelaeM4QqspEp21KoJCeQzpWHngqHW69x2/qz6GpeEJKdyW CfyCWTKXVLptWcVXZfvWdoZshzh2NAvVBISgkiLqnPGE32ywGD+vtDUhBl5gH34udAek mbWxE+WsVBxok4beN8Fj+woN02a4IYqF0W0x1fHD8z1DbiQPxANO0LHdbr/6AGIcHXxI U9dac2pdWtJSPI3dGqEPbTap6uPb8MyGJME9UkQ8NnO6rbyplv5qmMF/HU6sU8vc3Mop MtA+2k/espqFpLC1NXlnONnsSuC+tl2j57LCU50WG7bzzNGFxOfkF7uuHMwsFlO75Wl4 8RDw== 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=l/AE762kcZ5+fefPuuyQiLmzvis/P6HnGtNK2oQ0l8U=; b=Hqf/tT+z6+1eQCyiv7pU8XyVG8HQsoA8RLvj8EQGvJ8GlRnohuzbXwWqxyn1J9HsZr ErhCEkvFi2kz57BxMalTECKnxu0ugSUwLPHCdbC5NF7yFw8xDda4CjvFWoDK0nGbUN7+ RYXFLp54aUvWEyCmLglFXhvGYiu+syOpUIoYweozJkcp1oCHTrB864sByEtFiQq5Znsi vWs89lANcZaYL/TY/jpAOf6kyPwvDo9kQ22qWbmSJtX7mtS+DCiYv3kcRTRFQZoz5gUE SiIUcTp+xcFnOjiQrirzxvjl5RYBym2c/vAW0LdQHvPyFVleJoHC9+hh8665hkgK9+or IFyA== X-Gm-Message-State: AOAM533SsF/97udnC2kiYtEHmWlKr+PaRW0HskLJHY3FrBiKQbrsgzSS BUQ93hqj5s9nX0cUrxdwGJFyv8lK X-Google-Smtp-Source: ABdhPJyaYCL9P5qL948KUvSppIyG5/Z2m6jkvGAiwpmG+cMuwbDi9wcpj3md41sGN35SxkwF8DKiNA== X-Received: by 2002:a5d:6990:: with SMTP id g16mr49139732wru.131.1594206737429; Wed, 08 Jul 2020 04:12:17 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:16 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 08/20] fanotify: break up fanotify_alloc_event() Date: Wed, 8 Jul 2020 14:11:43 +0300 Message-Id: <20200708111156.24659-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-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 Reported-by: kernel test robot --- 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 921ff05e1877..c4ada3501014 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -344,6 +344,77 @@ static struct inode *fanotify_fid_inode(struct inode *to_tell, u32 event_mask, return 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, @@ -351,8 +422,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); @@ -372,55 +441,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 @@ -432,19 +469,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 Wed Jul 8 11:11:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651379 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 464BC13B4 for ; Wed, 8 Jul 2020 11:12:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 230B520739 for ; Wed, 8 Jul 2020 11:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mOlmjRwx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728776AbgGHLMV (ORCPT ); Wed, 8 Jul 2020 07:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMU (ORCPT ); Wed, 8 Jul 2020 07:12:20 -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 67380C08C5DC for ; Wed, 8 Jul 2020 04:12:20 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id a6so48494279wrm.4 for ; Wed, 08 Jul 2020 04:12:20 -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=6BLOVTFUs/XkZ6qUttQS+b8ADkcX5E4cpFoZFhr13Vo=; b=mOlmjRwxTbYBdKTbGevhj2hwFbO+cOpCu0cH5wPjH+ElCzuS9HZldHi38Z03oGP92T /CCFpPvV5GoRKMHtbaUu8HFTdKT4E6LzRFQpZ80FxHmgw7QjwLcAXQCGmFkzwJB3CA/v 641xi/AEE9QRRJggriJWID/axjQjT2tWq/SD7n9L8xQ0K+iRfdl+HLpnDlSsRh6ZFWug Rk9Gothzl3F79En25osTKVlh1+9SNToZqFT+kOpY+TVpNEuSn7tzfm9Y1f2BY9aE72+M rgO6AASNDlhqKdFuvX5yEhAg4cBDCy4kkBcf/EExXSJZy1OQ39b/lHMnQJiHnlWV/39w XUNQ== 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=6BLOVTFUs/XkZ6qUttQS+b8ADkcX5E4cpFoZFhr13Vo=; b=bg4c3B6O4vlVSoVPtl8E/WGXx5g6s/At38O2m7H8zLxDa/QLsrDIY43fi3w/xNP53H /6n3eAtQ8M/Cq5nx5Iu5czRcjV/3fjP01ptLchcLUg9ibQ3UQMXj4XVXeX3wi8DKeSE1 O1D7vh6nQtWWaliAst1jj3lEX/eGq4dRSarFzkAq9mjUWuzhG5t3c1PImwI5RWd9uJbZ HA9HcWomBGIUKRsxmYdtsvl4TmtMagJek9uExCq+aqKC5mUKSGqX9INKHc1YGI0XTMZO EIEaAxn+BWl6pMBznhc0V0C6ATgaALLa57g7AICm7TfoBIkPlYFX4oFdafoQQ2N9qPxm s+BA== X-Gm-Message-State: AOAM5308W5FTqElJaPYWX293jSLhWpVLKHgsRkTJ77kX4/SI2WBw0R17 /vOKx4/2l0gn/tczK/7m9JT0TVM+ X-Google-Smtp-Source: ABdhPJx9LgfFArpYjg8h7Gsm5VFX9EhU+qWLUFySLY763k0BRQemtgOKH8c96JeEW659894vhL8AGg== X-Received: by 2002:adf:f34f:: with SMTP id e15mr58844314wrp.415.1594206738766; Wed, 08 Jul 2020 04:12:18 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:18 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 09/20] fsnotify: pass dir argument to handle_event() callback Date: Wed, 8 Jul 2020 14:11:44 +0300 Message-Id: <20200708111156.24659-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The 'inode' argument to handle_event(), sometimes referred to as 'to_tell' is somewhat obsolete. It is a remnant from the times when a group could only have an inode mark associated with an event. We now pass an iter_info array to the callback, with all marks associated with an event. Most backends ignore this argument, with two exceptions: 1. dnotify uses it for sanity check that event is on directory 2. fanotify uses it to report fid of directory on directory entry modification events Remove the 'inode' argument and add a 'dir' argument. The callback function signature is deliberately changed, because the meaning of the argument has changed and the arguments have been documented. The 'dir' argument is NULL when "sending" to a non-dir inode. When 'file_name' argument is non NULL, 'dir' is always referring to the directory that the 'file_name' entry belongs to. Signed-off-by: Amir Goldstein --- fs/nfsd/filecache.c | 6 +++--- fs/notify/dnotify/dnotify.c | 8 ++++---- fs/notify/fanotify/fanotify.c | 23 +++++++++++------------ fs/notify/fsnotify.c | 26 ++++++++++++-------------- fs/notify/inotify/inotify.h | 6 +++--- fs/notify/inotify/inotify_fsnotify.c | 7 +++---- fs/notify/inotify/inotify_user.c | 4 ++-- include/linux/fsnotify_backend.h | 18 +++++++++++++++--- kernel/audit_fsnotify.c | 10 +++++----- kernel/audit_tree.c | 6 +++--- kernel/audit_watch.c | 6 +++--- 11 files changed, 64 insertions(+), 56 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ace8e5c30952..bbc7892d2928 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -598,9 +598,9 @@ static struct notifier_block nfsd_file_lease_notifier = { }; static int -nfsd_file_fsnotify_handle_event(struct fsnotify_group *group, - struct inode *to_tell, - u32 mask, const void *data, int data_type, +nfsd_file_fsnotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 7a42c2ebe28d..608c3e70e81f 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -70,9 +70,9 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark) * destroy the dnotify struct if it was not registered to receive multiple * events. */ -static int dnotify_handle_event(struct fsnotify_group *group, - struct inode *inode, - u32 mask, const void *data, int data_type, +static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { @@ -84,7 +84,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, __u32 test_mask = mask & ~FS_EVENT_ON_CHILD; /* not a dir, dnotify doesn't care */ - if (!S_ISDIR(inode->i_mode)) + if (!dir) return 0; if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info))) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index c4ada3501014..e68a9fad98bd 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -335,11 +335,11 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, * FS_ATTRIB reports the child inode even if reported on a watched parent. * 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) +static struct inode *fanotify_fid_inode(u32 event_mask, const void *data, + int data_type, struct inode *dir) { if (event_mask & ALL_FSNOTIFY_DIRENT_EVENTS) - return to_tell; + return dir; return fsnotify_data_inode(data, data_type); } @@ -416,14 +416,14 @@ struct fanotify_event *fanotify_alloc_name_event(struct inode *id, } static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, - struct inode *inode, u32 mask, - const void *data, int data_type, + u32 mask, const void *data, + int data_type, struct inode *dir, const struct qstr *file_name, __kernel_fsid_t *fsid) { struct fanotify_event *event = NULL; gfp_t gfp = GFP_KERNEL_ACCOUNT; - struct inode *id = fanotify_fid_inode(inode, mask, data, data_type); + struct inode *id = fanotify_fid_inode(mask, data, data_type, dir); const struct path *path = fsnotify_data_path(data, data_type); /* @@ -507,9 +507,9 @@ static __kernel_fsid_t fanotify_get_fsid(struct fsnotify_iter_info *iter_info) return fsid; } -static int fanotify_handle_event(struct fsnotify_group *group, - struct inode *inode, - u32 mask, const void *data, int data_type, +static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { @@ -546,8 +546,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, if (!mask) return 0; - pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode, - mask); + pr_debug("%s: group=%p mask=%x\n", __func__, group, mask); if (fanotify_is_perm_event(mask)) { /* @@ -565,7 +564,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, return 0; } - event = fanotify_alloc_event(group, inode, mask, data, data_type, + event = fanotify_alloc_event(group, mask, data, data_type, dir, file_name, &fsid); ret = -ENOMEM; if (unlikely(!event)) { diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 30628a72ca01..e05f3b2cf664 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -185,11 +185,9 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, } EXPORT_SYMBOL_GPL(__fsnotify_parent); -static int send_to_group(struct inode *to_tell, - __u32 mask, const void *data, - int data_is, u32 cookie, - const struct qstr *file_name, - struct fsnotify_iter_info *iter_info) +static int send_to_group(__u32 mask, const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, + u32 cookie, struct fsnotify_iter_info *iter_info) { struct fsnotify_group *group = NULL; __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); @@ -225,15 +223,14 @@ static int send_to_group(struct inode *to_tell, } } - pr_debug("%s: group=%p to_tell=%p mask=%x marks_mask=%x marks_ignored_mask=%x" - " data=%p data_is=%d cookie=%d\n", - __func__, group, to_tell, mask, marks_mask, marks_ignored_mask, - data, data_is, cookie); + pr_debug("%s: group=%p mask=%x marks_mask=%x marks_ignored_mask=%x data=%p data_type=%d dir=%p cookie=%d\n", + __func__, group, mask, marks_mask, marks_ignored_mask, + data, data_type, dir, cookie); if (!(test_mask & marks_mask & ~marks_ignored_mask)) return 0; - return group->ops->handle_event(group, to_tell, mask, data, data_is, + return group->ops->handle_event(group, mask, data, data_type, dir, file_name, cookie, iter_info); } @@ -317,12 +314,13 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) * out to all of the registered fsnotify_group. Those groups can then use the * notification event in whatever means they feel necessary. */ -int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, +int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, const struct qstr *file_name, u32 cookie) { - const struct path *path = fsnotify_data_path(data, data_is); + const struct path *path = fsnotify_data_path(data, data_type); struct fsnotify_iter_info iter_info = {}; struct super_block *sb = to_tell->i_sb; + struct inode *dir = S_ISDIR(to_tell->i_mode) ? to_tell : NULL; struct mount *mnt = NULL; int ret = 0; __u32 test_mask, marks_mask; @@ -375,8 +373,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, * That's why this traversal is so complicated... */ while (fsnotify_iter_select_report_types(&iter_info)) { - ret = send_to_group(to_tell, mask, data, data_is, cookie, - file_name, &iter_info); + ret = send_to_group(mask, data, data_type, dir, file_name, + cookie, &iter_info); if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) goto out; diff --git a/fs/notify/inotify/inotify.h b/fs/notify/inotify/inotify.h index 3f246f7b8a92..4327d0e9c364 100644 --- a/fs/notify/inotify/inotify.h +++ b/fs/notify/inotify/inotify.h @@ -24,9 +24,9 @@ static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse) extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark, struct fsnotify_group *group); -extern int inotify_handle_event(struct fsnotify_group *group, - struct inode *inode, - u32 mask, const void *data, int data_type, +extern int inotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info); diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index 9b481460a2dc..dfd455798a1b 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c @@ -55,9 +55,8 @@ static int inotify_merge(struct list_head *list, return event_compare(last_event, event); } -int inotify_handle_event(struct fsnotify_group *group, - struct inode *inode, - u32 mask, const void *data, int data_type, +int inotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { @@ -82,7 +81,7 @@ int inotify_handle_event(struct fsnotify_group *group, alloc_len += len + 1; } - pr_debug("%s: group=%p inode=%p mask=%x\n", __func__, group, inode, + pr_debug("%s: group=%p mark=%p mask=%x\n", __func__, group, inode_mark, mask); i_mark = container_of(inode_mark, struct inotify_inode_mark, diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index f88bbcc9efeb..5385d5817dd9 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -490,8 +490,8 @@ void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark, fsn_mark); /* Queue ignore event for the watch */ - inotify_handle_event(group, NULL, FS_IN_IGNORED, NULL, - FSNOTIFY_EVENT_NONE, NULL, 0, &iter_info); + inotify_handle_event(group, FS_IN_IGNORED, NULL, FSNOTIFY_EVENT_NONE, + NULL, NULL, 0, &iter_info); i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark); /* remove this mark from the idr */ diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 97300f3b8ff0..430d131d11c6 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -108,6 +108,19 @@ struct mem_cgroup; * these operations for each relevant group. * * handle_event - main call for a group to handle an fs event + * @group: group to notify + * @mask: event type and flags + * @data: object that event happened on + * @data_type: type of object for fanotify_data_XXX() accessors + * @dir: optional directory associated with event - + * if @file_name is not NULL, this is the directory that + * @file_name is relative to. Otherwise, @dir is the object + * inode if event happened on directory and NULL if event + * happenned on a non-directory. + * @file_name: optional file name associated with event + * @cookie: inotify rename cookie + * @iter_info: array of marks from this group that are interested in the event + * * free_group_priv - called when a group refcnt hits 0 to clean up the private union * freeing_mark - called when a mark is being destroyed for some reason. The group * MUST be holding a reference on each mark and that reference must be @@ -115,9 +128,8 @@ struct mem_cgroup; * userspace messages that marks have been removed. */ struct fsnotify_ops { - int (*handle_event)(struct fsnotify_group *group, - struct inode *inode, - u32 mask, const void *data, int data_type, + int (*handle_event)(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info); void (*free_group_priv)(struct fsnotify_group *group); diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index 3596448bfdab..30ca239285a3 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -152,11 +152,11 @@ static void audit_autoremove_mark_rule(struct audit_fsnotify_mark *audit_mark) } /* Update mark data in audit rules based on fsnotify events. */ -static int audit_mark_handle_event(struct fsnotify_group *group, - struct inode *to_tell, - u32 mask, const void *data, int data_type, - const struct qstr *dname, u32 cookie, - struct fsnotify_iter_info *iter_info) +static int audit_mark_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, + const struct qstr *dname, u32 cookie, + struct fsnotify_iter_info *iter_info) { struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); struct audit_fsnotify_mark *audit_mark; diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index e49c912f862d..2ce2ac1ce100 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c @@ -1037,9 +1037,9 @@ static void evict_chunk(struct audit_chunk *chunk) audit_schedule_prune(); } -static int audit_tree_handle_event(struct fsnotify_group *group, - struct inode *to_tell, - u32 mask, const void *data, int data_type, +static int audit_tree_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) { diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index e09c551ae52d..61fd601f1edf 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -464,9 +464,9 @@ void audit_remove_watch_rule(struct audit_krule *krule) } /* Update watch data in audit rules based on fsnotify events. */ -static int audit_watch_handle_event(struct fsnotify_group *group, - struct inode *to_tell, - u32 mask, const void *data, int data_type, +static int audit_watch_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *dname, u32 cookie, struct fsnotify_iter_info *iter_info) { From patchwork Wed Jul 8 11:11:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651381 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 9CEE2739 for ; Wed, 8 Jul 2020 11:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8134720771 for ; Wed, 8 Jul 2020 11:12:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q6RnHhZH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728790AbgGHLMX (ORCPT ); Wed, 8 Jul 2020 07:12:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMV (ORCPT ); Wed, 8 Jul 2020 07:12:21 -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 796EEC08C5DC for ; Wed, 8 Jul 2020 04:12:21 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id b6so48464299wrs.11 for ; Wed, 08 Jul 2020 04:12:21 -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=0RznM6V9EpewBz0nSAqAQ+u8DNu6bH6DPGPWPaSW9EE=; b=Q6RnHhZH/BgMuj9Mt7O37QN8HuJhjl0WkZTd5ecgdH6TY80tljDkJg2b9LhMj4m2+A Jql7D9ZTlPaOgUiEAo48S8rTw7EFQ6zeYJkaFCrrd/aWrT6PpqECpQR9/d+qR3/lpA58 Hl52v2oHcJNl+lajAa/88YYAwlJyMg/dbgyvbNAKivM5z82rkaDEKQp4i6GGTMutoo7f oXIpyPltbpDoP5B9+cW6+v6OPyKX2rVZ4xzgc5svo2cRaAz44eAfltBYcF2yXXKjHMqd oDzwF+7/t61Okqx9PzpjTbTaJ2b9RSZjOckFnHkgIxs7EokteQlK4fDkz3sy4hEX3Or7 ni+A== 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=0RznM6V9EpewBz0nSAqAQ+u8DNu6bH6DPGPWPaSW9EE=; b=Sq42GQIIBpjxbVC7Fyt/O+VCwovOec9XBc8ZkEcBBHic/N9o2A+Xz2BB1U1wFznK+8 yt5f3kLhoQ0jCTbI7UW+qIY62zvwPRjV3UUv3EgWu/2INLGr7YjnXrXL8qmhn9B7PrGH Crfvm3te3NMnd44IriRqMO4OrEjIPyG0FRwJDMNlUq92AW3wxGFNUG0mzfaeh6FmtzTv esxOm0SWGbHakLX2UfrGzQNehOmMyxY8ARatHsxBsEXEBkMzxuyE15WLkUwtf8QTaw7c kEAGWsV7GmZUWjdorIKrtKuRD8GQ1lnTixUQQRHVuNB7aw7BftxRFaK1b9shdbRX8om3 1PXQ== X-Gm-Message-State: AOAM530oQFi/6LgquDY+xmVQBYVnAI6UMD8AIkenbARWHS/Hds85acw5 E0+8atX5ddo/bfdwNeNGIMoZwc3w X-Google-Smtp-Source: ABdhPJwqBAeOADjUwqlE24OR6DWbopXVrWGgRPZaOAj0qiQPfoLMNBBWEPHr5YOLUDK00uBZ4cA5hw== X-Received: by 2002:adf:ea0f:: with SMTP id q15mr28063145wrm.113.1594206740260; Wed, 08 Jul 2020 04:12:20 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:19 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 10/20] fanotify: generalize the handling of extra event flags Date: Wed, 8 Jul 2020 14:11:45 +0300 Message-Id: <20200708111156.24659-10-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-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. We never report it to user, but we do pass it in to fanotify_alloc_event() when group is reporting fid as indication that event happened on child. We will have use for this indication later on. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index e68a9fad98bd..d853acc62b83 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -211,7 +211,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; @@ -264,14 +265,18 @@ 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. + * to user in 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() when group is reporting fid as indication + * that event happened on child. */ 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 Wed Jul 8 11:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651383 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 379C2739 for ; Wed, 8 Jul 2020 11:12:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FA0E20771 for ; Wed, 8 Jul 2020 11:12:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="etfGwhhk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728803AbgGHLMY (ORCPT ); Wed, 8 Jul 2020 07:12:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMX (ORCPT ); Wed, 8 Jul 2020 07:12:23 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44685C08C5DC for ; Wed, 8 Jul 2020 04:12:23 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id o8so2478588wmh.4 for ; Wed, 08 Jul 2020 04:12:23 -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=3TryVjoesZDaVZR8q3LIFPNDgn22PlUX35vntd9eriU=; b=etfGwhhk6BPIw2VO8J50ouWvq+RkEI7se+8/OcEr+zTvQOky3yDMyolLBi9emLvr8M JysVajr+CmFWcAMSe8wsppn7Nyc0qITLs8xk0vuuJsSdR46D2gt1EN0bBDcXbt1ZsnEq 93f3IBhbUntPUSC2Xim4Q2P5VZxXuchEnp2mYtj2TSV8Ob8LR1k0ZLEBERfqvXY8GHMW bwRe4hQmb62p1bbwPU6eF5VbSs3ZMC/CuRjNMXTNYR90eXW0YsI8gpUHVl7jbXxy/H9F rEe5ysiGxYvxGa73CArlTRsBAXVMuJPU5Ii9LCqRAWWZ+YuOkYuYj6wr4K3bum2rZALH Ghuw== 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=3TryVjoesZDaVZR8q3LIFPNDgn22PlUX35vntd9eriU=; b=UBWtYqtWUSLuK3A/LUm5x0ZZeBNcJH3Wmzi+McGBnjOrXFB21XnWaXeMBf/Kj4XzGX LzFCWqk3uSiMzIaRWxSnzkgLiDYo4MWpEEFWqY9KjIRCHiLV98s/04zvg0XGLIw1xjph BQ7ESIpCtkPQxBBOUyIhnFeTqB7mexxBNcqYXNeNZr8AwOiK4j80CQuCQYXi2hfy0E35 /UgLcdRD0d7lPbzwigkFPRK6D7JPAHmgIL2WrVHzQXNNanSI88Cq5Dj21Rb48388HaJv yge2iznZP3I88PYL/O/cM+Ntf4H2H7JqFWK2iK6qUPIZ1cBntmWhtXbXs3N1aNtH900y zZ/g== X-Gm-Message-State: AOAM530c/N6gmO+FDPke0a0Il2TqgL8++MdGfJ3KOeFHay/zSdQyrBRX JjWwpgKiIXtp0ldOWrC4SRA= X-Google-Smtp-Source: ABdhPJxl/IpODdPMLazYxT47nQrfGwYwXMsW1hDn2UNbiRyyd/QB+67KJP57QyB9JY4ZVy7UQrStvw== X-Received: by 2002:a1c:2982:: with SMTP id p124mr9231214wmp.26.1594206742034; Wed, 08 Jul 2020 04:12:22 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:21 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 11/20] fanotify: generalize merge logic of events on dir Date: Wed, 8 Jul 2020 14:11:46 +0300 Message-Id: <20200708111156.24659-11-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org An event on directory should never be merged with an event on non-directory regardless of the event struct type. This change has no visible effect, because currently, with struct fanotify_path_event, the relevant events will not be merged because event path of dir will be different than event path of non-dir. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index d853acc62b83..94316639cafb 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -83,22 +83,22 @@ static bool fanotify_should_merge(struct fsnotify_event *old_fsn, old->type != new->type || old->pid != new->pid) return false; + /* + * We want to merge many dirent events in the same dir (i.e. + * creates/unlinks/renames), but we do not want to merge dirent + * events referring to subdirs with dirent events referring to + * non subdirs, otherwise, user won't be able to tell from a + * mask FAN_CREATE|FAN_DELETE|FAN_ONDIR if it describes mkdir+ + * unlink pair or rmdir+create pair of events. + */ + if ((old->mask & FS_ISDIR) != (new->mask & FS_ISDIR)) + return false; + switch (old->type) { case FANOTIFY_EVENT_TYPE_PATH: return fanotify_path_equal(fanotify_event_path(old), fanotify_event_path(new)); case FANOTIFY_EVENT_TYPE_FID: - /* - * We want to merge many dirent events in the same dir (i.e. - * creates/unlinks/renames), but we do not want to merge dirent - * events referring to subdirs with dirent events referring to - * non subdirs, otherwise, user won't be able to tell from a - * mask FAN_CREATE|FAN_DELETE|FAN_ONDIR if it describes mkdir+ - * unlink pair or rmdir+create pair of events. - */ - if ((old->mask & FS_ISDIR) != (new->mask & FS_ISDIR)) - return false; - return fanotify_fid_event_equal(FANOTIFY_FE(old), FANOTIFY_FE(new)); case FANOTIFY_EVENT_TYPE_FID_NAME: From patchwork Wed Jul 8 11:11:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651385 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 4850913B4 for ; Wed, 8 Jul 2020 11:12:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 305F020772 for ; Wed, 8 Jul 2020 11:12:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O0aC90sm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728854AbgGHLMZ (ORCPT ); Wed, 8 Jul 2020 07:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLMZ (ORCPT ); Wed, 8 Jul 2020 07:12: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 9DD60C08C5DC for ; Wed, 8 Jul 2020 04:12:24 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id z2so26212412wrp.2 for ; Wed, 08 Jul 2020 04:12: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=yRQPB0bO5fRf+w+U7ylZ8gHdgwszFT8wyVGA9GecFLg=; b=O0aC90sm1cKdJOU8EXtxyXI5BDfnZEMaCQ9rQJBWIer15UEpOmlfDhYT9bk8QYSRIe o0H/3ZZXK8nfff+utOr8D3rl5Bs+osVUi57YgToPzIhCgVk19Io7szR9R+JkXWh1MOzR Ht6k9Vij0v67wrbSvDMXsaJgcf02kbSIr6kCzzMn6P/owPo1ZdgK5Dqn5TK7Ws3+eBh7 tUOkJeCFzM+JJYTrIzzvWCQ97j0GaQLepHJJGaVqa2AS18YRe5LQ75s3CbtqkmFtwzbc lcte2KdveL0Z0OR0k9eXWV1c9qr2FJbIMMksQcC7A6gjNmdze4Hvz3zPqsTY21UG9il3 L51g== 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=yRQPB0bO5fRf+w+U7ylZ8gHdgwszFT8wyVGA9GecFLg=; b=RzPp0PTfv0ImVbODOWkXRgw7qgqB+h4hrE0KZoV+4juAta8pjD1edoxAPWt5f+N/7d Gv0VUZIFIPenF+i6kmonAh//zf6cZeCHRu/xRXpNK+RDTcb818hKDByOtlon24TwD996 baO+WQM9cEQDFO7AtNmDXEMb/jCenGTbg9kiK4VY2J9Ib+OU3Oo0PPu/9Jtbe3pq/1eu VB4rK7sJM/oZNuUtausGoXO36cGSGYND7Bht9SLCBudgbhSfcA8ZykErs6n5cUA6lVUD cdrFhd8U3QA3rhcJ63lbGIksCyewof4NvM2avNx1WMKW7ngeLYbXem4qjr3I1okXYrtg qtTg== X-Gm-Message-State: AOAM530HEN1nEvIYzkIQOo+543zR7l0RT/Kvzp4WMQgPPJIiRN8BhkgD HciYEQn5uvFMcIlD2+bYkgo= X-Google-Smtp-Source: ABdhPJzzRBui7nw5H2Br2s9DvbwUPP0/xSyo7aQJpsrS+v15eNQ0jDNgiTR83RY/Uhdnj80n33Iu7g== X-Received: by 2002:adf:e74e:: with SMTP id c14mr61412355wrn.143.1594206743435; Wed, 08 Jul 2020 04:12:23 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:22 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 12/20] fanotify: distinguish between fid encode error and null fid Date: Wed, 8 Jul 2020 14:11:47 +0300 Message-Id: <20200708111156.24659-12-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-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 just a semantic difference at this point. Remove stale comment and unneeded check from fid event compare helpers. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 94316639cafb..ef8a1b698691 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -34,10 +34,6 @@ static bool fanotify_fh_equal(struct fanotify_fh *fh1, if (fh1->type != fh2->type || fh1->len != fh2->len) return false; - /* Do not merge events if we failed to encode fh */ - if (fh1->type == FILEID_INVALID) - return false; - return !fh1->len || !memcmp(fanotify_fh_buf(fh1), fanotify_fh_buf(fh2), fh1->len); } @@ -56,10 +52,7 @@ static bool fanotify_fid_event_equal(struct fanotify_fid_event *ffe1, static bool fanotify_name_event_equal(struct fanotify_name_event *fne1, struct fanotify_name_event *fne2) { - /* - * Do not merge name events without dir fh. - * FAN_DIR_MODIFY does not encode object fh, so it may be empty. - */ + /* Do not merge name events without dir fh */ if (!fne1->dir_fh.len) return false; @@ -290,8 +283,10 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, void *buf = fh->buf; int err; + fh->type = FILEID_ROOT; + fh->len = 0; if (!inode) - goto out; + return; dwords = 0; err = -ENOENT; @@ -326,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 Wed Jul 8 11:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651387 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 BD75213B4 for ; Wed, 8 Jul 2020 11:12:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FEFF20739 for ; Wed, 8 Jul 2020 11:12:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fVh1Cipp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728856AbgGHLM1 (ORCPT ); Wed, 8 Jul 2020 07:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLM0 (ORCPT ); Wed, 8 Jul 2020 07:12:26 -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 05F5BC08C5DC for ; Wed, 8 Jul 2020 04:12:26 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id q5so48445731wru.6 for ; Wed, 08 Jul 2020 04:12: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=oInbQVhRH555hPda+U4NJnZYtCjJvpWTosUFV8aGrRE=; b=fVh1CippflwH5/ASU4Zt9M8/F4WD0DP1DAcv1ePEYxU6/XKWEDYEArEOEmIHF+9V0U n7fprCJ02aZXFeAS+nbd4HsRyQz/CdL435Yk6laYFTaT9qMIF8QjwbdKrhxQPg38pR90 ZgYKaW8JCgtZZlRCN6oWcJDp/2OId/sBfqpDN+ZbF7/vNQXkSKIZmaDOn4czGCsfK6Py 3CvN2OOEkhNFRSV5+77mPz2+OXzro+vvUKrjeiPDjoAO38AIclMUhrzHyQdyHqL8ll4N P13+dekJi9c7vuUjGrexNECH9NPpfcyPeKG/FoP7o9xEFX60iKRD8LZdO0SFOZ/JRuUJ bPbw== 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=oInbQVhRH555hPda+U4NJnZYtCjJvpWTosUFV8aGrRE=; b=f6BzUDOTf9jIY2E8/NMchdLTqEYxHvEfHYAafcvYTOGKGptWqUB/1LZvmobnWCBww2 J+KzArBOSjRQ/i3clEEFFijWXTGQDaYkL1bs8KBX1GzwQxqpJBiQglQ+xkLCJ+7FtWXp pOhp8y7RA46iYQaWjZYzEUMa3Pyr9ODfysec0zDCLqSDPduF2/yZlpOdiQvQGl4jlG6T k4ejQ4raWvLulxgTPuLgpwm8qYc1gCLqC4yzmYf9ypVfKa3hc+TqucpBhxw1AXSXBYaH HZwKCshK6J6g6FwUH4c8HJ334nhgDUSgAilMWB/0kdjEo+Q7DlHErxeFur2gQgFBjH0S iAIw== X-Gm-Message-State: AOAM532Nse6hN+qrntyZmCNxlk0Ec97WDyxwYLP/AWTxA1qq/QVc+HvC FEZ+HQnEOkFC0Ns2FC3n3zk= X-Google-Smtp-Source: ABdhPJyDRqjjlmhUG8pFGZwIkXymGQQ4j8hfDglxDuVjniIzemVff0N07EuUKv4VGoETEsDeM9Eugg== X-Received: by 2002:adf:f6cb:: with SMTP id y11mr57266801wrp.100.1594206744647; Wed, 08 Jul 2020 04:12:24 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:24 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 13/20] fanotify: generalize test for FAN_REPORT_FID Date: Wed, 8 Jul 2020 14:11:48 +0300 Message-Id: <20200708111156.24659-13-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As preparation to new flags that report fids, define a bit set of flags for a group reporting fids, currently containing the only bit FAN_REPORT_FID. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 10 ++++++---- fs/notify/fanotify/fanotify_user.c | 12 ++++++------ include/linux/fanotify.h | 6 ++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index ef8a1b698691..3a82ddb63196 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -207,13 +207,14 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, __u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS | FANOTIFY_EVENT_FLAGS; const struct path *path = fsnotify_data_path(data, data_type); + unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); struct fsnotify_mark *mark; int type; pr_debug("%s: report_mask=%x mask=%x data=%p data_type=%d\n", __func__, iter_info->report_mask, event_mask, data, data_type); - if (!FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + if (!fid_mode) { /* Do we have path to open a file descriptor? */ if (!path) return 0; @@ -264,7 +265,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, * fanotify_alloc_event() when group is reporting fid as indication * that event happened on child. */ - if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + if (fid_mode) { /* Do not report event flags without any event */ if (!(test_mask & ~FANOTIFY_EVENT_FLAGS)) return 0; @@ -424,6 +425,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, gfp_t gfp = GFP_KERNEL_ACCOUNT; struct inode *id = fanotify_fid_inode(mask, data, data_type, dir); const struct path *path = fsnotify_data_path(data, data_type); + unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); /* * For queues with unlimited length lost events are not expected and @@ -448,7 +450,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, * 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)) { + } else if (fid_mode) { event = fanotify_alloc_fid_event(id, fsid, gfp); } else { event = fanotify_alloc_path_event(path, gfp); @@ -556,7 +558,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, return 0; } - if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) { fsid = fanotify_get_fsid(iter_info); /* Racing with mark destruction or creation? */ if (!fsid.val[0] && !fsid.val[1]) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8f3c70873598..92bb885b98b6 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -100,7 +100,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group, if (fsnotify_notify_queue_is_empty(group)) goto out; - if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) { event_size += fanotify_event_info_len( FANOTIFY_E(fsnotify_peek_first_event(group))); } @@ -877,7 +877,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) return -EINVAL; } - if ((flags & FAN_REPORT_FID) && + if ((flags & FANOTIFY_FID_BITS) && (flags & FANOTIFY_CLASS_BITS) != FAN_CLASS_NOTIF) return -EINVAL; @@ -1035,7 +1035,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, __kernel_fsid_t __fsid, *fsid = NULL; u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; - unsigned int obj_type; + unsigned int obj_type, fid_mode; int ret; pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", @@ -1108,9 +1108,9 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, * inode events are not supported on a mount mark, because they do not * carry enough information (i.e. path) to be filtered by mount point. */ + fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); if (mask & FANOTIFY_INODE_EVENTS && - (!FAN_GROUP_FLAG(group, FAN_REPORT_FID) || - mark_type == FAN_MARK_MOUNT)) + (!fid_mode || mark_type == FAN_MARK_MOUNT)) goto fput_and_out; if (flags & FAN_MARK_FLUSH) { @@ -1135,7 +1135,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, goto path_put_and_out; } - if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { + if (fid_mode) { ret = fanotify_test_fid(&path, &__fsid); if (ret) goto path_put_and_out; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index b79fa9bb7359..bbbee11d2521 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -18,8 +18,10 @@ #define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ FAN_CLASS_PRE_CONTENT) -#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ - FAN_REPORT_TID | FAN_REPORT_FID | \ +#define FANOTIFY_FID_BITS (FAN_REPORT_FID) + +#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | FANOTIFY_FID_BITS | \ + FAN_REPORT_TID | \ FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) From patchwork Wed Jul 8 11:11:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11651389 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 86DED739 for ; Wed, 8 Jul 2020 11:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E31D20772 for ; Wed, 8 Jul 2020 11:12:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fGTVd7QN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728861AbgGHLMb (ORCPT ); Wed, 8 Jul 2020 07:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728713AbgGHLM1 (ORCPT ); Wed, 8 Jul 2020 07:12: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 6E624C08C5DC for ; Wed, 8 Jul 2020 04:12:27 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id o11so48524732wrv.9 for ; Wed, 08 Jul 2020 04:12:27 -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=hZyrx3M5ZDXIIPFXTz1CL5MNCJNiQMk8YdSpmLrpHQI=; b=fGTVd7QNY6PdkO4y8KxqjdlXyLMwjuqmmBMA5c+ks432Q9vEkcyPISWsihuElbPA+O cP51s9sbVolnezE4bt2SJVQ84J32oLmreRK9tAtM0gJPULTWrUTb6h5zXzUgvWFq7ip8 2KxRu9wNjH2RP1ebC2wIyO/9QJGnycVtouUfReUlRkuHr2VnoVD04pUocttpowuYqmFH 9hz2NUHtYXNvz8+uPg1tdwNzGjpnvrKhn7kL//0kKEUeF4JNYU5SbRLU6s2xzjHJTwec POGo/9MA5iqvTbCa3z9SDOx+tnRg9pX7w3ess5lMR8qCA7k02AxiOaUULKXxIOguTZPB wDvQ== 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=hZyrx3M5ZDXIIPFXTz1CL5MNCJNiQMk8YdSpmLrpHQI=; b=bnvpi/+vi6Utm9XnT6CrAaKVcyJAa7x4iI1N3NBwptDpSmX1lbYsJ5YH3Wxfidkcw5 ZDV3GTNe1UVSbunRCWejU6g9KW8k/wYDOdFPQsyqG/zIEe2BH5KJOyFFNI/W/heC/HGw f4IDvhRWPqbfz0WpCTo1j+lepCJGNbveLxlbTouHuabpzm38F/wh+eTZRc+y+iBgApi9 2UIWvKNBo6mqIOeV9/PX1aJ3XCt0LiWijbHCMNxU8xLqgjOR9WX2jdShxy/qTOv3MnVi nLenWMdSJcuoGfe5yorXpv0BelJLKBhIIooMjyR6rfAFw+vJpEYzxq8VmgODgvB+n5Ae Y0TQ== X-Gm-Message-State: AOAM530IfMHAl+RIplCTYY0cxykCJNXJPsnAYzr9UmrPCIZ7otTlTgrm 8NkjLwHJ9uUL7wE6ZxpjuFu9xhTW X-Google-Smtp-Source: ABdhPJyhJsCB09o9AoNE/opDpk4QW0rwffRccQDBT3KSHjqjQSphwawKnnfr+uQ8BoEfSgL9uGQgkg== X-Received: by 2002:adf:8521:: with SMTP id 30mr55179186wrh.238.1594206746178; Wed, 08 Jul 2020 04:12:26 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:25 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 14/20] fanotify: mask out special event flags from ignored mask Date: Wed, 8 Jul 2020 14:11:49 +0300 Message-Id: <20200708111156.24659-14-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-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 event flags (FAN_ONDIR, FAN_EVENT_ON_CHILD) never had any meaning in ignored mask. Mask them out explicitly. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 92bb885b98b6..27bbd67270d8 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1035,6 +1035,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, __kernel_fsid_t __fsid, *fsid = NULL; u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; + bool ignored = flags & FAN_MARK_IGNORED_MASK; unsigned int obj_type, fid_mode; int ret; @@ -1082,6 +1083,10 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (mask & ~valid_mask) return -EINVAL; + /* Event flags (ONDIR, ON_CHILD) are meaningless in ignored mask */ + if (ignored) + mask &= ~FANOTIFY_EVENT_FLAGS; + f = fdget(fanotify_fd); if (unlikely(!f.file)) return -EBADF; From patchwork Wed Jul 8 11:11: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: 11651391 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 04D1B14E3 for ; Wed, 8 Jul 2020 11:12:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC7FE20772 for ; Wed, 8 Jul 2020 11:12:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YTsySCsp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728862AbgGHLMb (ORCPT ); Wed, 8 Jul 2020 07:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728857AbgGHLM3 (ORCPT ); Wed, 8 Jul 2020 07:12:29 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02EEBC08E6DC for ; Wed, 8 Jul 2020 04:12:29 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id j18so2489175wmi.3 for ; Wed, 08 Jul 2020 04:12: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=ATp/RTsI7zK8EGtjqOjVBnrsgD4PvuAHbXIa5Nq+0TQ=; b=YTsySCspQR9f1SgUwVeT7rV3fuJNjef0Gsm4zb8dhXEXTy+COUOXWTmM3s6/+FxeAj p9FAX2ju672xDRUDQ7HCEGc9XtoFIo0rWf2llPMxaXeJiJtnUfpS2+gAnG4pPrdIaipr 4md1KdzCHwgHjK/WpOlGrh/UcB9+NDcmxvNwHLuv8o2ttSOKbm6hc0R0ZIeF7KzzBBcS bmVrle0863qRkIt//QKXlj1r7kb+O6w/jPkrq1tywgkf3KbC0RrxQYErZsp4PYPyFhGH F4WaeZAJHICOL7QvlYbTtqPZE0Wy+URJKh36Pf1nGtLdCfOPdjba4Z947TSZdarYNJd6 tCBw== 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=ATp/RTsI7zK8EGtjqOjVBnrsgD4PvuAHbXIa5Nq+0TQ=; b=g8a0COrxY/Unj7bCiYxcz3v7yJ0D2htODdjwmp9vQma8UT2UXhDNfsN8iC2uEXVr9t rC+RDVL1rwSnyNuyMDNImbr5czETyXlUHL8hOz/vz6ajXK5BPUXL7dv5WqiczgOnO2q9 iEBcQ9PrergrKDTE8JK/vNGxzdHFEhc60BKiqKCV7A53yrrbeYB5GKaN+iIkPY1rQujS VDiTMmbbuYarcsPePknzqBLCQwBv4jzUwYzYhyoRVm/icoInkbkVKkG/tH8v3X6lCdlG rKR20WT7A4kSCCL+s8GM+JoL/4qdJg5Q/JogPk2uPobnbgZnv1aNHQutLP6h+iAozcg4 MeyA== X-Gm-Message-State: AOAM533sybUIU9e5xzq+sJDaxgZxm3Cy1VgBBrK2Zs8KIFjTe+uVGW9s 4Q8ggnw/2KY6ngyhPcow+IE= X-Google-Smtp-Source: ABdhPJwXNpzmf0+u0b+it/ovPRokUTAi6OKGgqrO31nFwNdcUW105VjePezaNvBc21+p0MT9OlkpDw== X-Received: by 2002:a1c:e088:: with SMTP id x130mr8446989wmg.14.1594206747726; Wed, 08 Jul 2020 04:12:27 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:26 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 15/20] fanotify: prepare for implicit event flags in mark mask Date: Wed, 8 Jul 2020 14:11:50 +0300 Message-Id: <20200708111156.24659-15-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org So far, all flags that can be set in an fanotify mark mask can be set explicitly by a call to fanotify_mark(2). Prepare for defining implicit event flags that cannot be set by user with fanotify_mark(2), similar to how inotify/dnotify implicitly set the FS_EVENT_ON_CHILD flag. Implicit event flags cannot be removed by user and mark gets destroyed when only implicit event flags remain in the mask. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 40 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 27bbd67270d8..66d663baa4a6 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -651,12 +651,13 @@ static int fanotify_find_path(int dfd, const char __user *filename, } static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, - __u32 mask, - unsigned int flags, - int *destroy) + __u32 mask, unsigned int flags, + __u32 umask, int *destroy) { __u32 oldmask = 0; + /* umask bits cannot be removed by user */ + mask &= ~umask; spin_lock(&fsn_mark->lock); if (!(flags & FAN_MARK_IGNORED_MASK)) { oldmask = fsn_mark->mask; @@ -664,7 +665,13 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, } else { fsn_mark->ignored_mask &= ~mask; } - *destroy = !(fsn_mark->mask | fsn_mark->ignored_mask); + /* + * We need to keep the mark around even if remaining mask cannot + * result in any events (e.g. mask == FAN_ONDIR) to support incremenal + * changes to the mask. + * Destroy mark when only umask bits remain. + */ + *destroy = !((fsn_mark->mask | fsn_mark->ignored_mask) & ~umask); spin_unlock(&fsn_mark->lock); return mask & oldmask; @@ -672,7 +679,7 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, static int fanotify_remove_mark(struct fsnotify_group *group, fsnotify_connp_t *connp, __u32 mask, - unsigned int flags) + unsigned int flags, __u32 umask) { struct fsnotify_mark *fsn_mark = NULL; __u32 removed; @@ -686,7 +693,7 @@ static int fanotify_remove_mark(struct fsnotify_group *group, } removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, - &destroy_mark); + umask, &destroy_mark); if (removed & fsnotify_conn_mask(fsn_mark->connector)) fsnotify_recalc_mask(fsn_mark->connector); if (destroy_mark) @@ -702,25 +709,26 @@ static int fanotify_remove_mark(struct fsnotify_group *group, static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, struct vfsmount *mnt, __u32 mask, - unsigned int flags) + unsigned int flags, __u32 umask) { return fanotify_remove_mark(group, &real_mount(mnt)->mnt_fsnotify_marks, - mask, flags); + mask, flags, umask); } static int fanotify_remove_sb_mark(struct fsnotify_group *group, - struct super_block *sb, __u32 mask, - unsigned int flags) + struct super_block *sb, __u32 mask, + unsigned int flags, __u32 umask) { - return fanotify_remove_mark(group, &sb->s_fsnotify_marks, mask, flags); + return fanotify_remove_mark(group, &sb->s_fsnotify_marks, mask, + flags, umask); } static int fanotify_remove_inode_mark(struct fsnotify_group *group, struct inode *inode, __u32 mask, - unsigned int flags) + unsigned int flags, __u32 umask) { return fanotify_remove_mark(group, &inode->i_fsnotify_marks, mask, - flags); + flags, umask); } static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, @@ -1170,13 +1178,13 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, case FAN_MARK_REMOVE: if (mark_type == FAN_MARK_MOUNT) ret = fanotify_remove_vfsmount_mark(group, mnt, mask, - flags); + flags, 0); else if (mark_type == FAN_MARK_FILESYSTEM) ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask, - flags); + flags, 0); else ret = fanotify_remove_inode_mark(group, inode, mask, - flags); + flags, 0); break; default: ret = -EINVAL; From patchwork Wed Jul 8 11:11: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: 11651393 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 26982739 for ; Wed, 8 Jul 2020 11:12:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DA1620771 for ; Wed, 8 Jul 2020 11:12:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mgr5RN4Y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbgGHLMc (ORCPT ); Wed, 8 Jul 2020 07:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728859AbgGHLMa (ORCPT ); Wed, 8 Jul 2020 07:12:30 -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 648A1C08E763 for ; Wed, 8 Jul 2020 04:12:30 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id b6so48464811wrs.11 for ; Wed, 08 Jul 2020 04:12: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=VsW8lp7Dft6LsK9pLejDbZ0bzJfNS3UHszpSp8npIxQ=; b=mgr5RN4YpRBwnuvc77hsUCP7K0DxILXfRtDoYSmhnms/BwbQYFQPHlnTskESYYhSDg FrIXum1hvqG09OduqHqZ8Gla2M+e8eCsQubvC1DqgA7pDAb9i/qJaOLz7hDVE2xoN8Il CpEaULxL0Qk8xPgjLJcIzGYsPn2VtJ1BrbfVEGagCArtXyn4p1j6Yl+su8uftuKlqBk0 9Mg8ya0bXIJak/qQAdmkSn/CW2I8zbsp1yMWAAmhUdkTcC1dZjTn60fN+5v5MEhaaeby 8fhPHmldiLwyB13keA8rPzEhVtlv5non9YjHay30+KJrWEOOYna1++0IkHnZWibHGyMh wMAg== 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=VsW8lp7Dft6LsK9pLejDbZ0bzJfNS3UHszpSp8npIxQ=; b=dADyqR/6gHxodaQao+xRdvJ9Vk0CRrbcgkzWaSSRlMK1KxHRKGk//nJMhWAY2wc+VW WhxwJdazc/DM++QEsmmF0ouu1uOiLNRKVOuxC+MsbBNz0TTniw04vkp3CQaE5lX7FDY2 vrj15WQCHhDo1JlLjf/hj3lBznntUixEmx5ti5lb5lEa5cVRkIsX53VJId5jdTkARRmb +d+eRK05Ps2M0qxbv71FknlTeIEqYh3IhpXHTS/g4bXgmzbZDHfq043Zj/p9KOD9crQg +cvHYuz3xG/LnIQGb0dvz5NATAxW6CR76BeHdQ4V2yKtvJOkg3t3zdtyDMTTRg8rkR8+ a2Mw== X-Gm-Message-State: AOAM530a8RFXXDlZ//u3rMNQIIEXYVO30dSYE5OJu1WQ+As/Oqa/pfYN rmuBRNPf+7/VmVy/RbxLytWO8DL8 X-Google-Smtp-Source: ABdhPJyeADImyv7hWLOTLkg+CPLRVNYGRvsBLo39Xwo4pi/xyBt/dZA+h0cOHIcXfBTn2YU8hgC+dg== X-Received: by 2002:adf:ea4f:: with SMTP id j15mr24191404wrn.253.1594206749193; Wed, 08 Jul 2020 04:12:29 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:28 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 16/20] fanotify: use FAN_EVENT_ON_CHILD as implicit flag on sb/mount/non-dir marks Date: Wed, 8 Jul 2020 14:11:51 +0300 Message-Id: <20200708111156.24659-16-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Up to now, fanotify allowed to set the FAN_EVENT_ON_CHILD flag on sb/mount marks and non-directory inode mask, but the flag was ignored. Mask out the flag if it is provided by user on sb/mount/non-dir marks and define it as an implicit flag that cannot be removed by user. This flag is going to be used internally to request for events with parent and name info. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 66d663baa4a6..42b8cc51cb3f 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1045,6 +1045,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; bool ignored = flags & FAN_MARK_IGNORED_MASK; unsigned int obj_type, fid_mode; + u32 umask = 0; int ret; pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", @@ -1162,6 +1163,12 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, else mnt = path.mnt; + /* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */ + if (mnt || !S_ISDIR(inode->i_mode)) { + mask &= ~FAN_EVENT_ON_CHILD; + umask = FAN_EVENT_ON_CHILD; + } + /* create/update an inode mark */ switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) { case FAN_MARK_ADD: @@ -1178,13 +1185,13 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, case FAN_MARK_REMOVE: if (mark_type == FAN_MARK_MOUNT) ret = fanotify_remove_vfsmount_mark(group, mnt, mask, - flags, 0); + flags, umask); else if (mark_type == FAN_MARK_FILESYSTEM) ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask, - flags, 0); + flags, umask); else ret = fanotify_remove_inode_mark(group, inode, mask, - flags, 0); + flags, umask); break; default: ret = -EINVAL; From patchwork Wed Jul 8 11:11: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: 11651395 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 C345E13B4 for ; Wed, 8 Jul 2020 11:12:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABEAF20772 for ; Wed, 8 Jul 2020 11:12:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nksO/NAJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728864AbgGHLMc (ORCPT ); Wed, 8 Jul 2020 07:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728679AbgGHLMc (ORCPT ); Wed, 8 Jul 2020 07:12:32 -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 D205CC08C5DC for ; Wed, 8 Jul 2020 04:12:31 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id q5so48446103wru.6 for ; Wed, 08 Jul 2020 04:12: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=SHcTUzc2xMMCSVX2qtFrRQqy5xK/SQtlJ+RwxoXkIZg=; b=nksO/NAJSKwmk/0zJ3qKx2HNfSEFir35n45TLOARDqDx5b/uMh/hBXDdEGrXP67aBD 377Kpxpp0UK16Xo26wupNPhRHCo1ZoN6tf4bhP3CTc+VrYPLwy24XDPfPDEaNo3B2Q82 fzzlRI+b9aZSK6xEqJGK+6o/rDboteziRFh8zCfcGDcckK0au3bppQRfMqxYCWUFEOg4 SqT/VEW7qPf2aCHzliJxBsxwa32hTG8OrFddE5oTK72B8/ly5wWsdCMsuYfacXzm1PKH P2TgsyuRMwAxfmx1ypAHpJVgiVfvwUw60nZBpk0bf7p6IZ1hr5ieE3rteIWF39oYYToV 46Sw== 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=SHcTUzc2xMMCSVX2qtFrRQqy5xK/SQtlJ+RwxoXkIZg=; b=dnBuKDNjI0Lv9MviMaEIL2ttx/89qD4+7mKqKqO5nTmUWTj+2GYSDbK0XYZeh+qIzx 5JLVuuCeV/0ohD6jShFz9DiyG5JMKNapvPQeSYLUb66fqABarkucUcz7tSfT92CxCpJQ kt0ELFKNGHLaY9ubetedb7tL603RMXpXw7mv47BR3BcExvE8tOFc0BZXVr3DkNWL3ZQW cRPe1wQ3Dc2/5p8F0K2rqKGzQdWYtmHgpxJHRTcakIbe12spKYS2KiX30Ter3BE+i6cA jCOfTFtYms88zL2YBJ8LKfnd+6W+CiwHzBwPJzm5hraz7/Yk10njQYRQ8+q4WlfTdhd9 +zxA== X-Gm-Message-State: AOAM531rYFP83aHvZKIV5AAJOHRi9PhVQqsO3i1xXXKztzqHgEnIvWHA +0X420FfMdJXOz0BFfg5wMTGweem X-Google-Smtp-Source: ABdhPJyq7PeN9/WW1CnjBKvVByHOWI0TgYAvUWFsJiiB5zhx7vwkI4c0dnYSlR+6YLlZKDiZeWfjig== X-Received: by 2002:adf:f34f:: with SMTP id e15mr58845352wrp.415.1594206750541; Wed, 08 Jul 2020 04:12:30 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:29 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 17/20] fanotify: remove event FAN_DIR_MODIFY Date: Wed, 8 Jul 2020 14:11:52 +0300 Message-Id: <20200708111156.24659-17-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org It was never enabled in uapi and its functionality is about to be superseded by events FAN_CREATE, FAN_DETELE, FAN_MOVE with group flag FAN_REPORT_NAME. Keep a place holder variable name_event instead of removing the name recording code. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 9 ++------- fs/notify/fsnotify.c | 2 +- include/linux/fsnotify.h | 6 ------ include/linux/fsnotify_backend.h | 4 +--- include/uapi/linux/fanotify.h | 1 - 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 3a82ddb63196..3885bf63976b 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -426,6 +426,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, struct inode *id = fanotify_fid_inode(mask, data, data_type, dir); const struct path *path = fsnotify_data_path(data, data_type); unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); + bool name_event = false; /* * For queues with unlimited length lost events are not expected and @@ -443,12 +444,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, if (fanotify_is_perm_event(mask)) { 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. - */ + } else if (name_event && file_name) { event = fanotify_alloc_name_event(id, fsid, file_name, gfp); } else if (fid_mode) { event = fanotify_alloc_fid_event(id, fsid, gfp); @@ -529,7 +525,6 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, BUILD_BUG_ON(FAN_MOVED_FROM != FS_MOVED_FROM); BUILD_BUG_ON(FAN_CREATE != FS_CREATE); BUILD_BUG_ON(FAN_DELETE != FS_DELETE); - BUILD_BUG_ON(FAN_DIR_MODIFY != FS_DIR_MODIFY); BUILD_BUG_ON(FAN_DELETE_SELF != FS_DELETE_SELF); BUILD_BUG_ON(FAN_MOVE_SELF != FS_MOVE_SELF); BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD); diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index e05f3b2cf664..51ada3cfd2ff 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -393,7 +393,7 @@ static __init int fsnotify_init(void) { int ret; - BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 26); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 25); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 316c9b820517..9b2566d273a9 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -30,12 +30,6 @@ static inline void fsnotify_name(struct inode *dir, __u32 mask, const struct qstr *name, u32 cookie) { fsnotify(dir, mask, child, FSNOTIFY_EVENT_INODE, name, cookie); - /* - * Send another flavor of the event without child inode data and - * without the specific event type (e.g. FS_CREATE|FS_IS_DIR). - * The name is relative to the dir inode the event is reported to. - */ - fsnotify(dir, FS_DIR_MODIFY, dir, FSNOTIFY_EVENT_INODE, name, 0); } static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 430d131d11c6..860c847c5bfa 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -47,7 +47,6 @@ #define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */ #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ -#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 @@ -67,8 +66,7 @@ * The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event * when a directory entry inside a child subdir changes. */ -#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | \ - FS_DIR_MODIFY) +#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE) #define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \ FS_OPEN_EXEC_PERM) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index a88c7c6d0692..7f2f17eacbf9 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -24,7 +24,6 @@ #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ -#define FAN_DIR_MODIFY 0x00080000 /* Directory entry was modified */ #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ From patchwork Wed Jul 8 11:11: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: 11651397 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 0E30113B4 for ; Wed, 8 Jul 2020 11:12:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E74B620739 for ; Wed, 8 Jul 2020 11:12:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZxBkH0Ju" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbgGHLMf (ORCPT ); Wed, 8 Jul 2020 07:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728679AbgGHLMd (ORCPT ); Wed, 8 Jul 2020 07:12:33 -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 15FB7C08C5DC for ; Wed, 8 Jul 2020 04:12:33 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id z2so26212966wrp.2 for ; Wed, 08 Jul 2020 04:12: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=nyv2KtM2WO7usNbqtN+HqdiLWba1gwwl7ImOSY7fMcw=; b=ZxBkH0JutqRhUErxyJt8b0YsLkeGYodjLpK0/oT3gp/ZVYtj2lJehrnQ+FmRne02zK 0pYoZZqyCglNeMa/3wNtJmoY8UVrx2CUkUCbasuIJcMeXzYS4NDM9djRM77tOu1LErqp xXb9AGz0ku4IXkfjX0PaOefz1axjyBzXh+AgP0qmjdz8utZ5tSem7S0zjsUMYslVKWRY N+P+tYRXtJpdvvZQWR1032yvDtzbRP734XDDqkglRva2PjIDe/7AexE5Y9MJ/1tJO1j9 giWjc/8FruWckFQHbW8BNDqVHPIH6llPWznlLL9/qIC8PPdF4JIEjKVLtaMj5GQhbT27 mn1Q== 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=nyv2KtM2WO7usNbqtN+HqdiLWba1gwwl7ImOSY7fMcw=; b=TJYhfxHne0Ves92s3mq9RP6DVxkdXc2VOXu7dQno/2/0BNh64vSuQC/DcTTjYE78pa 1vaxKA8eYJ9i+veycr0kJLOfExgBtzgBNRbVKeyR6z76exM8UVTITtSpD1LgKkcQLITE NpdOqaqQoGSquAii379lulogFRqQxZE0W0KacK2+zxua+liT7PiqVTCguww1jjAyTvAl bsDI9v4eou7ROEbDdP4Hx2qrcAgbjRzHuMIt2q6cPWAelHac6vkpOuqx9RV5MTrZo3P9 oUtYXC3PArD3txNuG9nI+EGCpW5q3raf4vw1IQQgxSkdm4coKYtC0D/wi/1+Op7sCv/R sB7A== X-Gm-Message-State: AOAM533X3gN2IBK9nkXQWBpR0G1a9GoXebmLYMIW4IzfeN2DaHqGBWwD J4xzy7Bj5VCVtgM8QO9FTqb/J7Pe X-Google-Smtp-Source: ABdhPJyIhYxX/45ZWx7aokPlm6c2DMyuoQUdQZwjVnjEeWsVkrYDFfHgF/4Oh1hcC0kUZX58/pCL3g== X-Received: by 2002:adf:ea0f:: with SMTP id q15mr28064113wrm.113.1594206751817; Wed, 08 Jul 2020 04:12:31 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:31 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 18/20] fsnotify: add object type "child" to object type iterator Date: Wed, 8 Jul 2020 14:11:53 +0300 Message-Id: <20200708111156.24659-18-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The object type iterator is used to collect all the marks of a specific group that have interest in an event. It is used by fanotify to get a single handle_event callback when an event has a match to either of inode/sb/mount marks of the group. The nature of fsnotify events is that they are associated with at most one sb at most one mount and at most one inode. When a parent and child are both watching, two events are sent to backend, one associated to parent inode and one associated to the child inode. This results in duplicate events in fanotify, which usually get merged before user reads them, but this is sub-optimal. It would be better if the same event is sent to backend with an object type iterator that has both the child inode and its parent, and let the backend decide if the event should be reported once (fanotify) or twice (inotify). Signed-off-by: Amir Goldstein --- include/linux/fsnotify_backend.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 860c847c5bfa..2c62628566c5 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -255,6 +255,7 @@ static inline const struct path *fsnotify_data_path(const void *data, enum fsnotify_obj_type { FSNOTIFY_OBJ_TYPE_INODE, + FSNOTIFY_OBJ_TYPE_CHILD, FSNOTIFY_OBJ_TYPE_VFSMOUNT, FSNOTIFY_OBJ_TYPE_SB, FSNOTIFY_OBJ_TYPE_COUNT, @@ -262,6 +263,7 @@ enum fsnotify_obj_type { }; #define FSNOTIFY_OBJ_TYPE_INODE_FL (1U << FSNOTIFY_OBJ_TYPE_INODE) +#define FSNOTIFY_OBJ_TYPE_CHILD_FL (1U << FSNOTIFY_OBJ_TYPE_CHILD) #define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT) #define FSNOTIFY_OBJ_TYPE_SB_FL (1U << FSNOTIFY_OBJ_TYPE_SB) #define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1) @@ -306,6 +308,7 @@ static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \ } FSNOTIFY_ITER_FUNCS(inode, INODE) +FSNOTIFY_ITER_FUNCS(child, CHILD) FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT) FSNOTIFY_ITER_FUNCS(sb, SB) From patchwork Wed Jul 8 11:11: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: 11651399 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 9EC1114E3 for ; Wed, 8 Jul 2020 11:12:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81B6620771 for ; Wed, 8 Jul 2020 11:12:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KAlL6rca" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728869AbgGHLMf (ORCPT ); Wed, 8 Jul 2020 07:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbgGHLMe (ORCPT ); Wed, 8 Jul 2020 07:12:34 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 726E7C08E6DC for ; Wed, 8 Jul 2020 04:12:34 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id f2so20494623wrp.7 for ; Wed, 08 Jul 2020 04:12:34 -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=8LiGJZ+tYUbX3WHjUWRCTZXgGPnYXxv67V/XKvaZ2Pg=; b=KAlL6rcafoDgj1TWsNtOq7AFnCMZtHagtGU+TjARQZAtvskveuetdIKrF7NUIDkzh+ tsZsmMVDYWCjjuPKF9862Vav4jNBGfmBsr5Rgc7HZq1nRYR0FiymFpVw3FZIYT38TKNU wlibaXefiUZHU0LFSs5JKEK5OoWgXQVETeaTvFSt6CO0B7uJAo5bxQV7mzczpCawDUuk p3HV+LO0IlCWlJMs+aAPt7txJqKN52fPHM0iS/il4dYYBqdIriqAc+OOR04tzS+9BoZz l7KF5GlM4/PfE361qSYLH4tvyfy7YFkCBsVkse5whP5f/0pHElp1i+xdJGiKbMaPQ/ca IARQ== 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=8LiGJZ+tYUbX3WHjUWRCTZXgGPnYXxv67V/XKvaZ2Pg=; b=XJsHyCvgfV/nl5v5XiLH5ZGheqIjGb4MQNCCNZxNZdl6Rlz2URDHfz50L/Lmkds3X1 7JxGJDU1BMUSHsk2tNoH+Osb89wYu2l0lOi22CIOrjXnXjLVPB1BnUwM8xFLHAf49hFE Lpkz3ItfJjiO6HKotBvhWukNzDYx0CSf2PUA4ElYz6uQm1pyYGQ7kW5KTpJZzqqCeEbF 97l26FtiWNC6mbi/wV8kOp6MgdU31caVQnc/SZxxBUVqK1p3plAWMDuwSsgezaX2oefL h7GdElVDDsBPj6ohrIGQROyqdUCPv+BpQdm9l8aAx/66u90Jxcup9puCsRd64ZQfnFfQ 8Vwg== X-Gm-Message-State: AOAM531SKT/BByFIOfoEjsBo4/aZD9wRc4cq1eAlIUbhu+Hfh8yahPby aIzw7l6Y4pt++dF5bteuG3dPahMD X-Google-Smtp-Source: ABdhPJxZUgZ73FrLJAUzgO2JU8WgUQuA08Rk4U6Uq2wuSBgKPEG+/9/vO80MqQzs0e2n0UnklY3/Gg== X-Received: by 2002:adf:e9c4:: with SMTP id l4mr60401223wrn.9.1594206753099; Wed, 08 Jul 2020 04:12:33 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:32 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 19/20] fanotify: use struct fanotify_info to parcel the variable size buffer Date: Wed, 8 Jul 2020 14:11:54 +0300 Message-Id: <20200708111156.24659-19-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org An fanotify event name is always recorded relative to a dir fh. Encapsulate the name_len member of fanotify_name_event in a new struct fanotify_info, which describes the parceling of the variable size buffer of an fanotify_name_event. The dir_fh member of fanotify_name_event is renamed to _dir_fh and is not accessed directly, but via the fanotify_info_dir_fh() accessor. Although the dir_fh len information is already available in struct fanotify_fh, we store it also in dif_fh_totlen member of fanotify_info, including the size of fanotify_fh header, so we know the offset of the name in the buffer without looking inside the dir_fh. We also add a file_fh_totlen member to allow packing another file handle in the variable size buffer after the dir_fh and before the name. We are going to use that space to store the child fid. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 66 ++++++++++++++++------ fs/notify/fanotify/fanotify.h | 91 +++++++++++++++++++++++++----- fs/notify/fanotify/fanotify_user.c | 25 ++++---- 3 files changed, 139 insertions(+), 43 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 3885bf63976b..4b0bc4afe6ff 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -49,22 +49,44 @@ static bool fanotify_fid_event_equal(struct fanotify_fid_event *ffe1, fanotify_fh_equal(&ffe1->object_fh, &ffe2->object_fh); } +static bool fanotify_info_equal(struct fanotify_info *info1, + struct fanotify_info *info2) +{ + if (info1->dir_fh_totlen != info2->dir_fh_totlen || + info1->file_fh_totlen != info2->file_fh_totlen || + info1->name_len != info2->name_len) + return false; + + if (info1->dir_fh_totlen && + !fanotify_fh_equal(fanotify_info_dir_fh(info1), + fanotify_info_dir_fh(info2))) + return false; + + if (info1->file_fh_totlen && + !fanotify_fh_equal(fanotify_info_file_fh(info1), + fanotify_info_file_fh(info2))) + return false; + + return !info1->name_len || + !memcmp(fanotify_info_name(info1), fanotify_info_name(info2), + info1->name_len); +} + static bool fanotify_name_event_equal(struct fanotify_name_event *fne1, struct fanotify_name_event *fne2) { - /* Do not merge name events without dir fh */ - if (!fne1->dir_fh.len) - return false; + struct fanotify_info *info1 = &fne1->info; + struct fanotify_info *info2 = &fne2->info; - if (fne1->name_len != fne2->name_len || - !fanotify_fh_equal(&fne1->dir_fh, &fne2->dir_fh)) + /* Do not merge name events without dir fh */ + if (!info1->dir_fh_totlen) return false; - return !memcmp(fne1->name, fne2->name, fne1->name_len); + return fanotify_info_equal(info1, info2); } static bool fanotify_should_merge(struct fsnotify_event *old_fsn, - struct fsnotify_event *new_fsn) + struct fsnotify_event *new_fsn) { struct fanotify_event *old, *new; @@ -276,8 +298,14 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, return test_mask & user_mask; } -static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, - gfp_t gfp) +/* + * Encode fanotify_fh. + * + * Return total size of encoded fh including fanotify_fh header. + * Return 0 on failure to encode. + */ +static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, + gfp_t gfp) { int dwords, type, bytes = 0; char *ext_buf = NULL; @@ -287,7 +315,7 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, fh->type = FILEID_ROOT; fh->len = 0; if (!inode) - return; + return 0; dwords = 0; err = -ENOENT; @@ -315,7 +343,7 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, fh->type = type; fh->len = bytes; - return; + return FANOTIFY_FH_HDR_LEN + bytes; out_err: pr_warn_ratelimited("fanotify: failed to encode fid (type=%d, len=%d, err=%i)\n", @@ -325,6 +353,7 @@ static void fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, /* Report the event without a file identifier on encode error */ fh->type = FILEID_INVALID; fh->len = 0; + return 0; } /* @@ -401,6 +430,8 @@ struct fanotify_event *fanotify_alloc_name_event(struct inode *id, gfp_t gfp) { struct fanotify_name_event *fne; + struct fanotify_info *info; + struct fanotify_fh *dfh; fne = kmalloc(sizeof(*fne) + file_name->len + 1, gfp); if (!fne) @@ -408,9 +439,11 @@ 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); - fne->name_len = file_name->len; - strcpy(fne->name, file_name->name); + info = &fne->info; + fanotify_info_init(info); + dfh = fanotify_info_dir_fh(info); + info->dir_fh_totlen = fanotify_encode_fh(dfh, id, gfp); + fanotify_info_copy_name(info, file_name); return &fne->fae; } @@ -626,9 +659,10 @@ static void fanotify_free_fid_event(struct fanotify_event *event) static void fanotify_free_name_event(struct fanotify_event *event) { struct fanotify_name_event *fne = FANOTIFY_NE(event); + struct fanotify_fh *dfh = fanotify_info_dir_fh(&fne->info); - if (fanotify_fh_has_ext_buf(&fne->dir_fh)) - kfree(fanotify_fh_ext_buf(&fne->dir_fh)); + if (fanotify_fh_has_ext_buf(dfh)) + kfree(fanotify_fh_ext_buf(dfh)); kfree(fne); } diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 1b2a3bbe6008..5e104fc56abb 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -23,11 +23,29 @@ enum { * stored in either the first or last 2 dwords. */ #define FANOTIFY_INLINE_FH_LEN (3 << 2) +#define FANOTIFY_FH_HDR_LEN offsetof(struct fanotify_fh, buf) +/* Fixed size struct for file handle */ struct fanotify_fh { - unsigned char buf[FANOTIFY_INLINE_FH_LEN]; u8 type; u8 len; + u8 pad[2]; + unsigned char buf[FANOTIFY_INLINE_FH_LEN]; +} __aligned(4); + +/* Variable size struct for dir file handle + child file handle + name */ +struct fanotify_info { + /* size of dir_fh/file_fh including fanotify_fh hdr size */ + u8 dir_fh_totlen; + u8 file_fh_totlen; + u8 name_len; + u8 pad; + unsigned char buf[]; + /* + * (struct fanotify_fh) dir_fh starts at buf[0] + * (optional) file_fh starts at buf[dir_fh_totlen] + * name starts at buf[dir_fh_totlen + file_fh_totlen] + */ } __aligned(4); static inline bool fanotify_fh_has_ext_buf(struct fanotify_fh *fh) @@ -37,6 +55,7 @@ static inline bool fanotify_fh_has_ext_buf(struct fanotify_fh *fh) static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh) { + BUILD_BUG_ON(FANOTIFY_FH_HDR_LEN % 4); BUILD_BUG_ON(__alignof__(char *) - 4 + sizeof(char *) > FANOTIFY_INLINE_FH_LEN); return (char **)ALIGN((unsigned long)(fh->buf), __alignof__(char *)); @@ -52,6 +71,56 @@ static inline void *fanotify_fh_buf(struct fanotify_fh *fh) return fanotify_fh_has_ext_buf(fh) ? fanotify_fh_ext_buf(fh) : fh->buf; } +static inline int fanotify_info_dir_fh_len(struct fanotify_info *info) +{ + if (!info->dir_fh_totlen || + WARN_ON_ONCE(info->dir_fh_totlen < FANOTIFY_FH_HDR_LEN)) + return 0; + + return info->dir_fh_totlen - FANOTIFY_FH_HDR_LEN; +} + +static inline struct fanotify_fh *fanotify_info_dir_fh(struct fanotify_info *info) +{ + BUILD_BUG_ON(offsetof(struct fanotify_info, buf) % 4); + + return (struct fanotify_fh *)info->buf; +} + +static inline int fanotify_info_file_fh_len(struct fanotify_info *info) +{ + if (!info->file_fh_totlen || + WARN_ON_ONCE(info->file_fh_totlen < FANOTIFY_FH_HDR_LEN)) + return 0; + + return info->file_fh_totlen - FANOTIFY_FH_HDR_LEN; +} + +static inline struct fanotify_fh *fanotify_info_file_fh(struct fanotify_info *info) +{ + return (struct fanotify_fh *)(info->buf + info->dir_fh_totlen); +} + +static inline const char *fanotify_info_name(struct fanotify_info *info) +{ + return info->buf + info->dir_fh_totlen + info->file_fh_totlen; +} + +static inline void fanotify_info_init(struct fanotify_info *info) +{ + info->dir_fh_totlen = 0; + info->file_fh_totlen = 0; + info->name_len = 0; +} + +static inline void fanotify_info_copy_name(struct fanotify_info *info, + const struct qstr *name) +{ + info->name_len = name->len; + strcpy(info->buf + info->dir_fh_totlen + info->file_fh_totlen, + name->name); +} + /* * Common structure for fanotify events. Concrete structs are allocated in * fanotify_handle_event() and freed when the information is retrieved by @@ -96,9 +165,9 @@ FANOTIFY_FE(struct fanotify_event *event) struct fanotify_name_event { struct fanotify_event fae; __kernel_fsid_t fsid; - struct fanotify_fh dir_fh; - u8 name_len; - char name[]; + struct fanotify_info info; + /* Reserve space in info.buf[] - access with fanotify_info_dir_fh() */ + struct fanotify_fh _dir_fh; }; static inline struct fanotify_name_event * @@ -126,11 +195,11 @@ static inline struct fanotify_fh *fanotify_event_object_fh( return NULL; } -static inline struct fanotify_fh *fanotify_event_dir_fh( +static inline struct fanotify_info *fanotify_event_info( struct fanotify_event *event) { if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME) - return &FANOTIFY_NE(event)->dir_fh; + return &FANOTIFY_NE(event)->info; else return NULL; } @@ -142,15 +211,11 @@ static inline int fanotify_event_object_fh_len(struct fanotify_event *event) return fh ? fh->len : 0; } -static inline bool fanotify_event_has_name(struct fanotify_event *event) +static inline int fanotify_event_dir_fh_len(struct fanotify_event *event) { - return event->type == FANOTIFY_EVENT_TYPE_FID_NAME; -} + struct fanotify_info *info = fanotify_event_info(event); -static inline int fanotify_event_name_len(struct fanotify_event *event) -{ - return fanotify_event_has_name(event) ? - FANOTIFY_NE(event)->name_len : 0; + return info ? fanotify_info_dir_fh_len(info) : 0; } struct fanotify_path_event { diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 42b8cc51cb3f..f490ebe913f3 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -66,19 +66,17 @@ static int fanotify_fid_info_len(int fh_len, int name_len) static int fanotify_event_info_len(struct fanotify_event *event) { - int info_len = 0; + struct fanotify_info *info = fanotify_event_info(event); + int dir_fh_len = fanotify_event_dir_fh_len(event); int fh_len = fanotify_event_object_fh_len(event); + int info_len = 0; + + if (dir_fh_len) + info_len += fanotify_fid_info_len(dir_fh_len, info->name_len); if (fh_len) info_len += fanotify_fid_info_len(fh_len, 0); - if (fanotify_event_name_len(event)) { - struct fanotify_name_event *fne = FANOTIFY_NE(event); - - info_len += fanotify_fid_info_len(fne->dir_fh.len, - fne->name_len); - } - return info_len; } @@ -305,6 +303,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, { struct fanotify_event_metadata metadata; struct path *path = fanotify_event_path(event); + struct fanotify_info *info = fanotify_event_info(event); struct file *f = NULL; int ret, fd = FAN_NOFD; @@ -346,13 +345,11 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, fd_install(fd, f); /* Event info records order is: dir fid + name, child fid */ - if (fanotify_event_name_len(event)) { - struct fanotify_name_event *fne = FANOTIFY_NE(event); - + if (fanotify_event_dir_fh_len(event)) { ret = copy_info_to_user(fanotify_event_fsid(event), - fanotify_event_dir_fh(event), - fne->name, fne->name_len, - buf, count); + fanotify_info_dir_fh(info), + fanotify_info_name(info), + info->name_len, buf, count); if (ret < 0) return ret; From patchwork Wed Jul 8 11:11: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: 11651401 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 0B09B739 for ; Wed, 8 Jul 2020 11:12:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E25812078A for ; Wed, 8 Jul 2020 11:12:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GmHlsnpw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728870AbgGHLMh (ORCPT ); Wed, 8 Jul 2020 07:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbgGHLMg (ORCPT ); Wed, 8 Jul 2020 07:12:36 -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 C3797C08C5DC for ; Wed, 8 Jul 2020 04:12:35 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id j4so46067256wrp.10 for ; Wed, 08 Jul 2020 04:12:35 -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=MvbXoBMoVypjtaPx+cxiAtbNly1n3Ipk++LuDqaVkZ8=; b=GmHlsnpw4dlR/IlunGIMkh2Y6qxXw5AW298KeGrxOKN3BEUtqwtPe4ZZOg3V5XLQA2 GArAHtF7A10727T8QFJuubu2bFl5Qp1MFhlT5VoM1ArTXNq3wg2SwC/9ttXLEeE8EVG4 4gp4EtPie38e5vcSNBVYVhG5Z/smnHVTlLeK1hJP5dBE2K1zWlpFFT+vBaLQxrEXhsK4 gsLKAz1Eva42ured0TM2nqI+SFDCw/F+jltmF8qUcgOYdIOohaAm1TmYd+nlzqz+kdgn 3hJFmN+rKI3IoCGS0T+VEDBZCPSMe3wENtBiJuBGV+K2Ie1sUCa3HIgIFeNKC5521/oF IwyQ== 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=MvbXoBMoVypjtaPx+cxiAtbNly1n3Ipk++LuDqaVkZ8=; b=eZv/gpIwMdZjVUqnUnKDf0q1HEaswfi7S5e0j2MfRtxJQdQqhgf/sA82ipXxgbjOlC A0mADYqmPec9Fl6E4mkyyzSsuZQqWDCjB7E073IEr1r2DtC6CdeNAWB2DEG8m453lX8S NfNfk1Y7rS4UpULxleNi7Cydydh5+jztY8xZ8SH0L2kLkbWPN7mh6vXHgW+ihkbo12m6 qjAiB22vHtKXwNZLx9aDOhcheAsp05HLg/kqlN784JgvpyPm3nOKHZppr58+eFnfEtGX +GRQvg0Sxu2jrKzILO6j0pbl5uh62nLJq6FpdqY4db868Pf7UAtx41Tcd+BDiert0t82 6n0Q== X-Gm-Message-State: AOAM531efjWzSw+nr+iGQq+/fiK8zu5yltnBUcQFCDEz9+zUHDg8exX1 7ctD44Ru4wBiNZEJxrpDWlE= X-Google-Smtp-Source: ABdhPJzpp35LBi/VuPKqSePqzDPhP+ox90b+NvmR9aY11e9zjlggveOt0UoPW3TtXwYZ8n16K639vQ== X-Received: by 2002:adf:e546:: with SMTP id z6mr54140751wrm.99.1594206754525; Wed, 08 Jul 2020 04:12:34 -0700 (PDT) Received: from localhost.localdomain ([141.226.183.23]) by smtp.gmail.com with ESMTPSA id k126sm5980834wme.17.2020.07.08.04.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:12:33 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 20/20] fanotify: no external fh buffer in fanotify_name_event Date: Wed, 8 Jul 2020 14:11:55 +0300 Message-Id: <20200708111156.24659-20-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200708111156.24659-1-amir73il@gmail.com> References: <20200708111156.24659-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The fanotify_fh struct has an inline buffer of size 12 which is enough to store the most common local filesystem file handles (e.g. ext4, xfs). For file handles that do not fit in the inline buffer (e.g. btrfs), an external buffer is allocated to store the file handle. When allocating a variable size fanotify_name_event, there is no point in allocating also an external fh buffer when file handle does not fit in the inline buffer. Check required size for encoding fh, preallocate an event buffer sufficient to contain both file handle and name and store the name after the file handle. At this time, when not reporting name in event, we still allocate the fixed size fanotify_fid_event and an external buffer for large file handles, but fanotify_alloc_name_event() has already been prepared to accept a NULL file_name. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 68 +++++++++++++++++++++++++---------- fs/notify/fanotify/fanotify.h | 12 ++++--- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 4b0bc4afe6ff..4833d4c88122 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -298,6 +298,24 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, return test_mask & user_mask; } +/* + * Check size needed to encode fanotify_fh. + * + * Return size of encoded fh without fanotify_fh header. + * Return 0 on failure to encode. + */ +static int fanotify_encode_fh_len(struct inode *inode) +{ + int dwords = 0; + + if (!inode) + return 0; + + exportfs_encode_inode_fh(inode, NULL, &dwords, NULL); + + return dwords << 2; +} + /* * Encode fanotify_fh. * @@ -305,27 +323,34 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, * Return 0 on failure to encode. */ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, - gfp_t gfp) + unsigned int fh_len, gfp_t gfp) { - int dwords, type, bytes = 0; + int dwords, bytes, type = 0; char *ext_buf = NULL; void *buf = fh->buf; int err; fh->type = FILEID_ROOT; fh->len = 0; + fh->flags = 0; if (!inode) return 0; - dwords = 0; + /* + * !gpf means preallocated variable size fh, but fh_len could + * be zero in that case if encoding fh len failed. + */ err = -ENOENT; - type = exportfs_encode_inode_fh(inode, NULL, &dwords, NULL); - if (!dwords) + if (!gfp) + bytes = fh_len; + else + bytes = fanotify_encode_fh_len(inode); + if (bytes < 4 || WARN_ON_ONCE(bytes % 4)) goto out_err; - bytes = dwords << 2; - if (bytes > FANOTIFY_INLINE_FH_LEN) { - /* Treat failure to allocate fh as failure to allocate event */ + /* No external buffer in a variable size allocated fh */ + if (gfp && bytes > FANOTIFY_INLINE_FH_LEN) { + /* Treat failure to allocate fh as failure to encode fh */ err = -ENOMEM; ext_buf = kmalloc(bytes, gfp); if (!ext_buf) @@ -333,8 +358,10 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, *fanotify_fh_ext_buf_ptr(fh) = ext_buf; buf = ext_buf; + fh->flags |= FANOTIFY_FH_FLAG_EXT_BUF; } + dwords = bytes >> 2; type = exportfs_encode_inode_fh(inode, buf, &dwords, NULL); err = -EINVAL; if (!type || type == FILEID_INVALID || bytes != dwords << 2) @@ -419,7 +446,7 @@ struct fanotify_event *fanotify_alloc_fid_event(struct inode *id, ffe->fae.type = FANOTIFY_EVENT_TYPE_FID; ffe->fsid = *fsid; - fanotify_encode_fh(&ffe->object_fh, id, gfp); + fanotify_encode_fh(&ffe->object_fh, id, 0, gfp); return &ffe->fae; } @@ -432,8 +459,13 @@ struct fanotify_event *fanotify_alloc_name_event(struct inode *id, struct fanotify_name_event *fne; struct fanotify_info *info; struct fanotify_fh *dfh; + unsigned int dir_fh_len = fanotify_encode_fh_len(id); + unsigned int size; - fne = kmalloc(sizeof(*fne) + file_name->len + 1, gfp); + size = sizeof(*fne) + FANOTIFY_FH_HDR_LEN + dir_fh_len; + if (file_name) + size += file_name->len + 1; + fne = kmalloc(size, gfp); if (!fne) return NULL; @@ -442,8 +474,13 @@ struct fanotify_event *fanotify_alloc_name_event(struct inode *id, info = &fne->info; fanotify_info_init(info); dfh = fanotify_info_dir_fh(info); - info->dir_fh_totlen = fanotify_encode_fh(dfh, id, gfp); - fanotify_info_copy_name(info, file_name); + info->dir_fh_totlen = fanotify_encode_fh(dfh, id, dir_fh_len, 0); + if (file_name) + fanotify_info_copy_name(info, file_name); + + pr_debug("%s: ino=%lu size=%u dir_fh_len=%u name_len=%u name='%.*s'\n", + __func__, id->i_ino, size, dir_fh_len, + info->name_len, info->name_len, fanotify_info_name(info)); return &fne->fae; } @@ -658,12 +695,7 @@ static void fanotify_free_fid_event(struct fanotify_event *event) static void fanotify_free_name_event(struct fanotify_event *event) { - struct fanotify_name_event *fne = FANOTIFY_NE(event); - struct fanotify_fh *dfh = fanotify_info_dir_fh(&fne->info); - - if (fanotify_fh_has_ext_buf(dfh)) - kfree(fanotify_fh_ext_buf(dfh)); - kfree(fne); + kfree(FANOTIFY_NE(event)); } static void fanotify_free_event(struct fsnotify_event *fsn_event) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 5e104fc56abb..12c204b1489f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -29,8 +29,10 @@ enum { struct fanotify_fh { u8 type; u8 len; - u8 pad[2]; - unsigned char buf[FANOTIFY_INLINE_FH_LEN]; +#define FANOTIFY_FH_FLAG_EXT_BUF 1 + u8 flags; + u8 pad; + unsigned char buf[]; } __aligned(4); /* Variable size struct for dir file handle + child file handle + name */ @@ -50,7 +52,7 @@ struct fanotify_info { static inline bool fanotify_fh_has_ext_buf(struct fanotify_fh *fh) { - return fh->len > FANOTIFY_INLINE_FH_LEN; + return (fh->flags & FANOTIFY_FH_FLAG_EXT_BUF); } static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh) @@ -154,6 +156,8 @@ struct fanotify_fid_event { struct fanotify_event fae; __kernel_fsid_t fsid; struct fanotify_fh object_fh; + /* Reserve space in object_fh.buf[] - access with fanotify_fh_buf() */ + unsigned char _inline_fh_buf[FANOTIFY_INLINE_FH_LEN]; }; static inline struct fanotify_fid_event * @@ -166,8 +170,6 @@ struct fanotify_name_event { struct fanotify_event fae; __kernel_fsid_t fsid; struct fanotify_info info; - /* Reserve space in info.buf[] - access with fanotify_info_dir_fh() */ - struct fanotify_fh _dir_fh; }; static inline struct fanotify_name_event *