From patchwork Wed Nov 14 17:43:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10682951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA4E8109C for ; Wed, 14 Nov 2018 17:43:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE4DA28521 for ; Wed, 14 Nov 2018 17:43:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2B5A28ABB; Wed, 14 Nov 2018 17:43:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 343CD286CF for ; Wed, 14 Nov 2018 17:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728021AbeKODsE (ORCPT ); Wed, 14 Nov 2018 22:48:04 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:56101 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727576AbeKODsE (ORCPT ); Wed, 14 Nov 2018 22:48:04 -0500 Received: by mail-wm1-f65.google.com with SMTP id i73-v6so11026770wmd.5 for ; Wed, 14 Nov 2018 09:43:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1ts4Cvr3O9dADF7T4wTj5zkNnTJnlrvaMmGYdfr718I=; b=ZmmirjAjAbzhelvOgTCjQ9pq9OgNXVZwiWb4ZM6/EqQEnxTqQLKZC7DKDYcEu2JKXI eCvmH434aCQigmCo3lstQzmHLEIOVZ1HPt2nM9MYGHPRquLKtwjVQnsGETWSPqNEMpXh EzpJrs6UnF+pYJCVa5kzIxA2GLj1gdbWlmNDiX2XysCjlaD7rhxyWr+7MPPcW+10Wige rRjqCpQATobK/4oW0tPLKsS+u8n26T+BHvxifcwCg9rVv2sNX2O0t07HCLl0+1hn51gF 2YIwiIVlE1Ni1ug0O5nnBjGwI8/QYQDXzshBFWNQVfL599psb6RqsdCL+P5ASfR+knaN sWFQ== 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=1ts4Cvr3O9dADF7T4wTj5zkNnTJnlrvaMmGYdfr718I=; b=io/aqNl2WMxI37XmRAKs52z6EEZ88sYJIxzskFk0y7u/WdCfTeC2EUjax8DF7UClLJ Xw/OIB/Ih5ln4bYcp4fCrxOdsm49sLYCvgxOWPMUDt27TC/1QE7G73g8T9lpzmhD5wKv mbcp55aP6r8QFqVjWQkDtm/yS9EVAGh+aR0O2RGiFoYVgbQmHyV/y8rNkq7m42Mtt8lN UBZfeIt3H66NzLIXxPgPdsYm3hQyNNVkwTeTUbmU/FoH/bxhGTccSX8Uaqdgy50GdTc1 4GqZYLTJVqRSM5Ra9Gfec72cfFI89KNcliBIMF/MXji7HtFCNAoOxGfrxU0WlzexsXK+ B4dA== X-Gm-Message-State: AGRZ1gI30wffLEzctSDlTQV2pxoR3/xORQ1sTek0nFFEeHgvtn+4KQGU dQh67bP42O3lrzbJXljQDUg= X-Google-Smtp-Source: AJdET5fBL5Z8Rd4Tt2IV7d8y5SetdCPmMUOAbB1UWUaG3E6Kc/DPtb7zuZviD1YgaT7du0MtH302jA== X-Received: by 2002:a1c:90cf:: with SMTP id s198-v6mr2659739wmd.124.1542217433467; Wed, 14 Nov 2018 09:43:53 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id d18-v6sm8587887wre.25.2018.11.14.09.43.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:43:52 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 1/5] fsnotify: pass dentry instead of inode when available Date: Wed, 14 Nov 2018 19:43:40 +0200 Message-Id: <20181114174344.17530-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114174344.17530-1-amir73il@gmail.com> References: <20181114174344.17530-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Define a new data type to pass for event FSNOTIFY_EVENT_DENTRY and use it whenever a dentry is available instead of passing it's ->d_inode as data type FSNOTIFY_EVENT_INODE. None of the current fsnotify backends make use of the inode data with data type FSNOTIFY_EVENT_INODE - only the data of type FSNOTIFY_EVENT_PATH is ever used, so this change has no immediate consequences. Soon, we are going to use the dentry data type to support more events with fanotify backend. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 8 ++++---- include/linux/fsnotify.h | 15 +++++++-------- include/linux/fsnotify_backend.h | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index ecf09b6243d9..6a120b7f8b94 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -178,11 +178,11 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask take_dentry_name_snapshot(&name, dentry); if (path) - ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH, - name.name, 0); + ret = fsnotify(p_inode, mask, path, + FSNOTIFY_EVENT_PATH, name.name, 0); else - ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, - name.name, 0); + ret = fsnotify(p_inode, mask, dentry, + FSNOTIFY_EVENT_DENTRY, name.name, 0); release_dentry_name_snapshot(&name); } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 2ccb08cb5d6a..9dadc0bcd7a9 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -99,14 +99,14 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); - fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name, + fsnotify(new_dir, new_dir_mask, moved, FSNOTIFY_EVENT_DENTRY, new_name, fs_cookie); if (target) fsnotify_link_count(target); if (source) - fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, NULL, 0); audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); } @@ -155,7 +155,7 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) { audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); + fsnotify(inode, FS_CREATE, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); } /* @@ -168,7 +168,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct fsnotify_link_count(inode); audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0); + fsnotify(dir, FS_CREATE, new_dentry, FSNOTIFY_EVENT_DENTRY, new_dentry->d_name.name, 0); } /* @@ -177,11 +177,10 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) { __u32 mask = (FS_CREATE | FS_ISDIR); - struct inode *d_inode = dentry->d_inode; audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); + fsnotify(inode, mask, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); } /* @@ -262,7 +261,7 @@ static inline void fsnotify_xattr(struct dentry *dentry) mask |= FS_ISDIR; fsnotify_parent(NULL, dentry, mask); - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify(inode, mask, dentry, FSNOTIFY_EVENT_DENTRY, NULL, 0); } /* @@ -297,7 +296,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) mask |= FS_ISDIR; fsnotify_parent(NULL, dentry, mask); - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify(inode, mask, dentry, FSNOTIFY_EVENT_DENTRY, NULL, 0); } } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 7639774e7475..24d92455be03 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -208,10 +208,11 @@ struct fsnotify_group { }; }; -/* when calling fsnotify tell it if the data is a path or inode */ +/* when calling fsnotify tell it if the data is a path or inode or dentry */ #define FSNOTIFY_EVENT_NONE 0 #define FSNOTIFY_EVENT_PATH 1 #define FSNOTIFY_EVENT_INODE 2 +#define FSNOTIFY_EVENT_DENTRY 3 enum fsnotify_obj_type { FSNOTIFY_OBJ_TYPE_INODE, From patchwork Wed Nov 14 17:43:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10682953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A38D109C for ; Wed, 14 Nov 2018 17:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DED3286CF for ; Wed, 14 Nov 2018 17:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31F9128779; Wed, 14 Nov 2018 17:43:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5C1128C18 for ; Wed, 14 Nov 2018 17:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728045AbeKODsG (ORCPT ); Wed, 14 Nov 2018 22:48:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44685 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727969AbeKODsF (ORCPT ); Wed, 14 Nov 2018 22:48:05 -0500 Received: by mail-wr1-f68.google.com with SMTP id j17-v6so18235782wrq.11 for ; Wed, 14 Nov 2018 09:43:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G5tz+3UHFxOku2Z7Ad1KUeU5GUWx9GURUbOYX/27thQ=; b=gBFy/+rXrYVBAq/777pKFtg23MaWFRwvb/rEKHfZ8J3D4ceRXW1wAWWPc5nFn+ullu gjcCZEWEpY8ev3WF1yMv5VaPGELuZOB8qAbm/w8zXD+DNsJsDxcN4UWMNIlOW636AAN1 sAjI3p2y9wGIjKKWss1hB1YnZ0D5JQ3s2mxTmUzHldbbLWZ2JM/bqSQSp5nwCw+q23mg XyKup7AHu7PrE3FPLMzs7m+5dNRWYk+X1gwuITEjXvsIfk0kU/xYt34r6okRPzvwoqsS kDVKMlns6aoTcENP3bqg57XFCFzuRqi0OmQmFdIN0sdD9GLK/X1Z3YSvy5iIp7w9wz9P umcQ== 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=G5tz+3UHFxOku2Z7Ad1KUeU5GUWx9GURUbOYX/27thQ=; b=hprT46CSwgYtGT6M38hCZTGf9nq07FKPLS/khKYiu5q4qHTxuEBrdPjnfKpJsTBGTl 3ZU8u2m+t/lngysCc5KZHl0OWkWRFgzAOVEiqArLCH/DcJqVoBvrPCZXD9SY4ldsa/rq q+u4drJ3bpSjbzsoynbYtGNGh1XeewQpTiELEEvouzpy8KqNx2rxxm8Td7ITMz56K4bp tC3TGgZrR/Wz7si+Qt1OsyUyrcl/ptwWHbtP1Y/qyMyGU0V6Apnz0JCJ/H26RHIoNIU8 SJJMgn0tdbtLNAQjGb2ptPEaB3XBCdXlA20nI3yMxPMfEx+Rvh71EvIsTpN9kl5WWgwI Z/PA== X-Gm-Message-State: AGRZ1gImd0bm4rMcF/q3VXQRMt0JKteuVW972fB+zDpm5kNSePT8rMQY t8MbwOCO631JLi3mT/kA+WQ= X-Google-Smtp-Source: AJdET5fpHIPA3ZB6LKKnDyKIpagyr6KfYWcsZGea+8i7NewqLAftq8bfCii6Spornc1GznbN9oeuDQ== X-Received: by 2002:a5d:6a0e:: with SMTP id m14-v6mr2859337wru.76.1542217435423; Wed, 14 Nov 2018 09:43:55 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id d18-v6sm8587887wre.25.2018.11.14.09.43.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:43:54 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 2/5] fsnotify: annotate filename events Date: Wed, 14 Nov 2018 19:43:41 +0200 Message-Id: <20181114174344.17530-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114174344.17530-1-amir73il@gmail.com> References: <20181114174344.17530-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Filename events are referring to events that modify directory entries, such as create,delete,rename. Those events should always be reported on a watched directory, regardless if FS_EVENT_ON_CHILD is set on the watch mask. fsnotify_nameremove() and fsnotify_move() were modified to no longer set the FS_EVENT_ON_CHILD event bit. This is a semantic change to align with the filename event definition. It has no effect on any existing backend, because dnotify and inotify always requets the child events and fanotify does not get the delete,rename events. The fsnotify_filename() helper is used to report all the filename events. It gets a reference on parent dentry and passes it as the data for the event along with the filename. fsnotify_filename() is different from fsnotify_parent(). fsnotify_parent() is intended to report any events that happened on child inodes when FS_EVENT_ON_CHILD is requested. fsnotify_filename() is intended to report only filename events, such as create,mkdir,link. Those events must always be reported on a watched directory, regardless if FS_EVENT_ON_CHILD was requested. fsnotify_d_name() is a helper for the common case where the filename to pass is dentry->d_name.name. It is safe to use these helpers with negative or not instantiated dentries, such as the case with fsnotify_link() and fsnotify_nameremove(). Signed-off-by: Amir Goldstein --- include/linux/fsnotify.h | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 9dadc0bcd7a9..d00ec5838d6e 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -17,8 +17,31 @@ #include #include +/* + * Notify this parent about a filename event (create,delete,rename). + * Unlike fsnotify_parent(), the event will be reported regardless of the + * FS_EVENT_ON_CHILD mask on the parent inode + */ +static inline int fsnotify_filename(struct dentry *parent, __u32 mask, + const unsigned char *file_name, u32 cookie) +{ + return fsnotify(d_inode(parent), mask, parent, FSNOTIFY_EVENT_DENTRY, + file_name, cookie); +} + +/* + * Call fsnotify_filename() with parent and d_name of this dentry. + * Safe to call with negative dentry, e.g. from fsnotify_nameremove() + */ +static inline int fsnotify_d_name(struct dentry *dentry, __u32 mask) +{ + return fsnotify_filename(dentry->d_parent, mask, + dentry->d_name.name, 0); +} + /* Notify this dentry's parent about a child's events. */ -static inline int fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask) +static inline int fsnotify_parent(const struct path *path, + struct dentry *dentry, __u32 mask) { if (!dentry) dentry = path->dentry; @@ -85,8 +108,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, { struct inode *source = moved->d_inode; u32 fs_cookie = fsnotify_get_cookie(); - __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); - __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); + __u32 old_dir_mask = FS_MOVED_FROM; + __u32 new_dir_mask = FS_MOVED_TO; const unsigned char *new_name = moved->d_name.name; if (old_dir == new_dir) @@ -99,8 +122,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); - fsnotify(new_dir, new_dir_mask, moved, FSNOTIFY_EVENT_DENTRY, new_name, - fs_cookie); + fsnotify_filename(moved->d_parent, new_dir_mask, new_name, fs_cookie); if (target) fsnotify_link_count(target); @@ -136,7 +158,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) if (isdir) mask |= FS_ISDIR; - fsnotify_parent(NULL, dentry, mask); + fsnotify_d_name(dentry, mask); } /* @@ -155,7 +177,7 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) { audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, FS_CREATE, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); + fsnotify_d_name(dentry, FS_CREATE); } /* @@ -168,7 +190,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct fsnotify_link_count(inode); audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(dir, FS_CREATE, new_dentry, FSNOTIFY_EVENT_DENTRY, new_dentry->d_name.name, 0); + fsnotify_d_name(new_dentry, FS_CREATE); } /* @@ -180,7 +202,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, mask, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); + fsnotify_d_name(dentry, mask); } /* From patchwork Wed Nov 14 17:43:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10682955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 945F0109C for ; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8826C287C0 for ; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CA4E2BDA1; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEBA028ABB for ; Wed, 14 Nov 2018 17:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728085AbeKODsI (ORCPT ); Wed, 14 Nov 2018 22:48:08 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33443 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbeKODsI (ORCPT ); Wed, 14 Nov 2018 22:48:08 -0500 Received: by mail-wm1-f67.google.com with SMTP id f19-v6so14071039wmb.0 for ; Wed, 14 Nov 2018 09:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tAF+X2KtLPneGT+bWcsbGFgHe3thUibIoIw0rNMbhWc=; b=Z8M3QGNb/yUXCJkEf81ax0XBx3xSaCACL9X5z/JJjRSM+JiHiQKC+0QucLTqdXH3lf 5QGZR04B2aZ8dCDY8URoq3dWztfHbzPP4WvYltXnxdnFx2na1sWVhULvqUVtoycqRKER B3EpRrmG8SQbccI0Kh7qSVvKOFGA+/MKO8zKaKUldBofJDi+7PzNcUT7/DOUBRUHz4hK DYqtzb+RJ9tbint+4GbrFDgothcYmlkteJdd84lJ3kd2s6VD9fPGjCioIQCsyw4n0s4d kW/Kaxu0NGtCiiC6tGMMWghmFJaj5lVIRKBGUKfIhg2AxKnBahzvg8IYEbzlZOu0Htkz ehwg== 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=tAF+X2KtLPneGT+bWcsbGFgHe3thUibIoIw0rNMbhWc=; b=k1/c6sqY86F2gSDxbwE2VlRaJSoAWGZ+B8faZFFCaub43C/daT8CGaHK34G+c3woUj 28QP7LsntHHElRovIeA4Wn0vcb5hZG9Pu2ftA+577Bko+4pIGr40lcsxzSGIIh/TYbOt PcbWYxnvWBNwuy1dZ2kwbnagbABanRp6lzA/H3T0EMi8lQBR8k1qAVzvxI4X3W0ggpfg JwXZCRDhg+NuDbJQm3irr6v18tKfw0sOEBPnUopT7/uDLTEjgeKHc6RUiw6siWYBhMTA 0x3J4joe9RCvFlIGDowRNRunzwwNvpF39eJhkQxyO1wC3AHCvUNZvbTsy+FCD1y7uZBI 2ZhQ== X-Gm-Message-State: AGRZ1gKyhiguhwGSAnYaD7yXoCvWp0tcbBd806kNo/nHidgcXqROG83t TdtimJlxcxEj+Tw5gylmQEu4Ttfg X-Google-Smtp-Source: AJdET5ebQPVcxe3HSWPly+3U13pAFCx33dmUgs/cltPbkBDxf/urcn3kxZsk0GhptY8GYgm47ACj9A== X-Received: by 2002:a7b:c052:: with SMTP id u18-v6mr2610636wmc.29.1542217437008; Wed, 14 Nov 2018 09:43:57 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id d18-v6sm8587887wre.25.2018.11.14.09.43.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:43:56 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 3/5] fsnotify: simplify API for filename events Date: Wed, 14 Nov 2018 19:43:42 +0200 Message-Id: <20181114174344.17530-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114174344.17530-1-amir73il@gmail.com> References: <20181114174344.17530-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not pass redundant parent inode arg. Signed-off-by: Amir Goldstein --- arch/powerpc/platforms/cell/spufs/inode.c | 2 +- fs/btrfs/ioctl.c | 2 +- fs/debugfs/inode.c | 6 +++--- fs/devpts/inode.c | 2 +- fs/namei.c | 18 +++++++++--------- fs/ocfs2/refcounttree.c | 2 +- fs/tracefs/inode.c | 4 ++-- include/linux/fsnotify.h | 20 +++++++++++++------- net/sunrpc/rpc_pipe.c | 6 +++--- 9 files changed, 34 insertions(+), 28 deletions(-) diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c index db329d4bf1c3..a40de703f586 100644 --- a/arch/powerpc/platforms/cell/spufs/inode.c +++ b/arch/powerpc/platforms/cell/spufs/inode.c @@ -587,7 +587,7 @@ long spufs_create(struct path *path, struct dentry *dentry, ret = spufs_create_context(dir, dentry, path->mnt, flags, mode, filp); if (ret >= 0) - fsnotify_mkdir(dir, dentry); + fsnotify_mkdir(dentry); return ret; } diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 802a628e9f7d..8af6258cb0a2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -979,7 +979,7 @@ static noinline int btrfs_mksubvol(const struct path *parent, async_transid, inherit); } if (!error) - fsnotify_mkdir(dir, dentry); + fsnotify_mkdir(dentry); out_up_read: up_read(&fs_info->subvol_sem); out_dput: diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 13b01351dd1c..ca9945f7db59 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -361,7 +361,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode, DEBUGFS_FSDATA_IS_REAL_FOPS_BIT); d_instantiate(dentry, inode); - fsnotify_create(d_inode(dentry->d_parent), dentry); + fsnotify_create(dentry); return end_creating(dentry); } @@ -520,7 +520,7 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) inc_nlink(inode); d_instantiate(dentry, inode); inc_nlink(d_inode(dentry->d_parent)); - fsnotify_mkdir(d_inode(dentry->d_parent), dentry); + fsnotify_mkdir(dentry); return end_creating(dentry); } EXPORT_SYMBOL_GPL(debugfs_create_dir); @@ -559,7 +559,7 @@ struct dentry *debugfs_create_automount(const char *name, inc_nlink(inode); d_instantiate(dentry, inode); inc_nlink(d_inode(dentry->d_parent)); - fsnotify_mkdir(d_inode(dentry->d_parent), dentry); + fsnotify_mkdir(dentry); return end_creating(dentry); } EXPORT_SYMBOL(debugfs_create_automount); diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index c53814539070..f15a33399a5b 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -589,7 +589,7 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv) if (dentry) { dentry->d_fsdata = priv; d_add(dentry, inode); - fsnotify_create(d_inode(root), dentry); + fsnotify_create(dentry); } else { iput(inode); dentry = ERR_PTR(-ENOMEM); diff --git a/fs/namei.c b/fs/namei.c index 0cab6494978c..1d743adf90a0 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2911,7 +2911,7 @@ int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, return error; error = dir->i_op->create(dir, dentry, mode, want_excl); if (!error) - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return error; } EXPORT_SYMBOL(vfs_create); @@ -2932,7 +2932,7 @@ int vfs_mkobj(struct dentry *dentry, umode_t mode, return error; error = f(dentry, mode, arg); if (!error) - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return error; } EXPORT_SYMBOL(vfs_mkobj); @@ -3081,7 +3081,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, int acc_mode = op->acc_mode; if (file->f_mode & FMODE_CREATED) { WARN_ON(!(open_flag & O_CREAT)); - fsnotify_create(dir, dentry); + fsnotify_create(dentry); acc_mode = 0; } error = may_open(&file->f_path, acc_mode, open_flag); @@ -3095,7 +3095,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, dentry = file->f_path.dentry; } if (file->f_mode & FMODE_CREATED) - fsnotify_create(dir, dentry); + fsnotify_create(dentry); if (unlikely(d_is_negative(dentry))) { error = -ENOENT; } else { @@ -3235,7 +3235,7 @@ static int lookup_open(struct nameidata *nd, struct path *path, open_flag & O_EXCL); if (error) goto out_dput; - fsnotify_create(dir_inode, dentry); + fsnotify_create(dentry); } if (unlikely(create_error) && !dentry->d_inode) { error = create_error; @@ -3718,7 +3718,7 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) error = dir->i_op->mknod(dir, dentry, mode, dev); if (!error) - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return error; } EXPORT_SYMBOL(vfs_mknod); @@ -3816,7 +3816,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) error = dir->i_op->mkdir(dir, dentry, mode); if (!error) - fsnotify_mkdir(dir, dentry); + fsnotify_mkdir(dentry); return error; } EXPORT_SYMBOL(vfs_mkdir); @@ -4126,7 +4126,7 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname) error = dir->i_op->symlink(dir, dentry, oldname); if (!error) - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return error; } EXPORT_SYMBOL(vfs_symlink); @@ -4248,7 +4248,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de } inode_unlock(inode); if (!error) - fsnotify_link(dir, inode, new_dentry); + fsnotify_link(inode, new_dentry); return error; } EXPORT_SYMBOL(vfs_link); diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index a35259eebc56..7ff695d1a3e4 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c @@ -4417,7 +4417,7 @@ static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, error = ocfs2_reflink(old_dentry, dir, new_dentry, preserve); inode_unlock(inode); if (!error) - fsnotify_create(dir, new_dentry); + fsnotify_create(new_dentry); return error; } /* diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7098c49f3693..4644ddc77595 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -410,7 +410,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, inode->i_fop = fops ? fops : &tracefs_file_operations; inode->i_private = data; d_instantiate(dentry, inode); - fsnotify_create(dentry->d_parent->d_inode, dentry); + fsnotify_create(dentry); return end_creating(dentry); } @@ -435,7 +435,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, inc_nlink(inode); d_instantiate(dentry, inode); inc_nlink(dentry->d_parent->d_inode); - fsnotify_mkdir(dentry->d_parent->d_inode, dentry); + fsnotify_mkdir(dentry); return end_creating(dentry); } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index d00ec5838d6e..4fb2fa0b31d2 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -63,6 +63,12 @@ static inline int fsnotify_path(struct inode *inode, const struct path *path, return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); } +static inline void audit_dentry_child(const struct dentry *dentry, + const unsigned char type) +{ + audit_inode_child(d_inode(dentry->d_parent), dentry, type); +} + /* Simple call site for access decisions */ static inline int fsnotify_perm(struct file *file, int mask) { @@ -129,7 +135,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, if (source) fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, NULL, 0); - audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); + audit_dentry_child(moved, AUDIT_TYPE_CHILD_CREATE); } /* @@ -173,9 +179,9 @@ static inline void fsnotify_inoderemove(struct inode *inode) /* * fsnotify_create - 'name' was linked in */ -static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) +static inline void fsnotify_create(struct dentry *dentry) { - audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); + audit_dentry_child(dentry, AUDIT_TYPE_CHILD_CREATE); fsnotify_d_name(dentry, FS_CREATE); } @@ -185,10 +191,10 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) * Note: We have to pass also the linked inode ptr as some filesystems leave * new_dentry->d_inode NULL and instantiate inode pointer later */ -static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) +static inline void fsnotify_link(struct inode *inode, struct dentry *new_dentry) { fsnotify_link_count(inode); - audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); + audit_dentry_child(new_dentry, AUDIT_TYPE_CHILD_CREATE); fsnotify_d_name(new_dentry, FS_CREATE); } @@ -196,11 +202,11 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct /* * fsnotify_mkdir - directory 'name' was created */ -static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) +static inline void fsnotify_mkdir(struct dentry *dentry) { __u32 mask = (FS_CREATE | FS_ISDIR); - audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); + audit_dentry_child(dentry, AUDIT_TYPE_CHILD_CREATE); fsnotify_d_name(dentry, mask); } diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 4fda18d47e2c..2dc1a0054c40 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -524,7 +524,7 @@ static int __rpc_create(struct inode *dir, struct dentry *dentry, err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private); if (err) return err; - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return 0; } @@ -539,7 +539,7 @@ static int __rpc_mkdir(struct inode *dir, struct dentry *dentry, if (err) return err; inc_nlink(dir); - fsnotify_mkdir(dir, dentry); + fsnotify_mkdir(dentry); return 0; } @@ -594,7 +594,7 @@ static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, rpci = RPC_I(d_inode(dentry)); rpci->private = private; rpci->pipe = pipe; - fsnotify_create(dir, dentry); + fsnotify_create(dentry); return 0; } From patchwork Wed Nov 14 17:43:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10682957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7CFB14D6 for ; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBA30279E0 for ; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C040F28ABB; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E67F289CA for ; Wed, 14 Nov 2018 17:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbeKODsJ (ORCPT ); Wed, 14 Nov 2018 22:48:09 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39757 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727576AbeKODsJ (ORCPT ); Wed, 14 Nov 2018 22:48:09 -0500 Received: by mail-wm1-f67.google.com with SMTP id u13-v6so15576623wmc.4 for ; Wed, 14 Nov 2018 09:43:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cvOl0Sp1ZtUdFvM9BhtEeh8nwJLb+E3PtSb/CjgeygA=; b=lp3Jd5+6eAbu8ZL7LSdfuPRAeyfyRc52nV9eLUMJifmuad/4+zcCeou+qXIYQUswa4 6EwI6wiYYIxxpJT+SG7HcUD6SP+13IRVEmRGeO8Gu3KQCxE5KHsipiamTXk/LVsHPuXV gZJyVTsDjHkzh8ybDkCNccB9IAn8xneYLf6ehJkLmEVkcwUTgNEqqKiSl50DyXg1bSCa mtdOda5SLgx+c4jED4+qC86ky4XCeJGIlrXhb8QBmBk5Q+ntGOb5phQBP4CMpi519Jr0 gLrobqwme5cRv5O/dxoQgqqxvVPYCFxpfJUkBS0Bbns45ysk4UFYqSrlNNeQzWWovVSN Up8g== 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=cvOl0Sp1ZtUdFvM9BhtEeh8nwJLb+E3PtSb/CjgeygA=; b=ahIb3wLm6U8Z+WSZN1CmgzlDxVKoQaVn/tgYPHBAJhGdyopxh9+vs/95YA/2QnHiDk ph69zt8lyrrBGblejAhsB9I/495KN+5D8DEf7sZvYgqgb7LlWMB0BqaglKdNOiwgeAU4 hqLjp0ffabIFRbcPqKzbJBy5IS17zR9ULBlfgaKBw2uH2iCGO8EzzxRM2Z2ALo/gvsDd 5lnKSIl3r5ST8ArUNQkEOnTDXa+en/2efYEHyXyTVl9nx/wjXgP2SbHZm2ztS8mJPIY0 gdMXPfDtu2IL5bIOk5SutoeatvAsV/6LsTUU3mvX+y0L+zNaaRJn9ZARLQGZbcuXB63U es1Q== X-Gm-Message-State: AGRZ1gIuSjN3rCYqoA9tZTj93jLmMp/Qad62rXSTZQLzX0tkQsVdgxbV ae9Bx99qBb9WywmhEwXgyNM= X-Google-Smtp-Source: AJdET5czaPL1OKhuMDo8M2W8zIIVNUplxdT0abV2xOSzbzcemetcx9qy1d0cTjJyNqREuUS7qIACjg== X-Received: by 2002:a1c:1189:: with SMTP id 131-v6mr2644888wmr.87.1542217438658; Wed, 14 Nov 2018 09:43:58 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id d18-v6sm8587887wre.25.2018.11.14.09.43.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:43:58 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 4/5] fsnotify: make MOVED_FROM a dentry event Date: Wed, 14 Nov 2018 19:43:43 +0200 Message-Id: <20181114174344.17530-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114174344.17530-1-amir73il@gmail.com> References: <20181114174344.17530-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Propagate old/new parent dentries to fsnotify_move() and pass old parent dentry as FSNOTIFY_EVENT_DENTRY info of MOVED_FROM event. This change has no effect on current backends. Soon, this will allow fanotify backend to get MOVED_FROM events. Signed-off-by: Amir Goldstein --- fs/debugfs/inode.c | 5 ++--- fs/namei.c | 10 +++++++--- include/linux/fsnotify.h | 18 +++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index ca9945f7db59..f7c061485f89 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -809,9 +809,8 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, goto exit; } d_move(old_dentry, dentry); - fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name.name, - d_is_dir(old_dentry), - NULL, old_dentry); + fsnotify_move(old_dir, new_dir, old_name.name, + d_is_dir(old_dentry), NULL, old_dentry); release_dentry_name_snapshot(&old_name); unlock_rename(new_dir, old_dir); dput(dentry); diff --git a/fs/namei.c b/fs/namei.c index 1d743adf90a0..ecaabc081cac 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4394,6 +4394,8 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, { int error; bool is_dir = d_is_dir(old_dentry); + struct dentry *old_parent = old_dentry->d_parent; + struct dentry *new_parent = new_dentry->d_parent; struct inode *source = old_dentry->d_inode; struct inode *target = new_dentry->d_inode; bool new_is_dir = false; @@ -4500,10 +4502,12 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, inode_unlock(target); dput(new_dentry); if (!error) { - fsnotify_move(old_dir, new_dir, old_name.name, is_dir, - !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry); + fsnotify_move(old_parent, new_parent, old_name.name, is_dir, + !(flags & RENAME_EXCHANGE) ? target : NULL, + old_dentry); if (flags & RENAME_EXCHANGE) { - fsnotify_move(new_dir, old_dir, old_dentry->d_name.name, + fsnotify_move(new_parent, old_parent, + old_dentry->d_name.name, new_is_dir, NULL, new_dentry); } } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 4fb2fa0b31d2..7d7629f99c9d 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -108,17 +108,17 @@ static inline void fsnotify_link_count(struct inode *inode) /* * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir */ -static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, - const unsigned char *old_name, - int isdir, struct inode *target, struct dentry *moved) +static inline void fsnotify_move(struct dentry *old_dir, struct dentry *new_dir, + const unsigned char *old_name, int isdir, + struct inode *target, struct dentry *moved) { - struct inode *source = moved->d_inode; + struct inode *source = d_inode(moved); u32 fs_cookie = fsnotify_get_cookie(); __u32 old_dir_mask = FS_MOVED_FROM; __u32 new_dir_mask = FS_MOVED_TO; const unsigned char *new_name = moved->d_name.name; - if (old_dir == new_dir) + if (d_inode(old_dir) == d_inode(new_dir)) old_dir_mask |= FS_DN_RENAME; if (isdir) { @@ -126,15 +126,15 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, new_dir_mask |= FS_ISDIR; } - fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, - fs_cookie); - fsnotify_filename(moved->d_parent, new_dir_mask, new_name, fs_cookie); + fsnotify_filename(old_dir, old_dir_mask, old_name, fs_cookie); + fsnotify_filename(new_dir, new_dir_mask, new_name, fs_cookie); if (target) fsnotify_link_count(target); if (source) - fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, NULL, 0); + fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, + NULL, 0); audit_dentry_child(moved, AUDIT_TYPE_CHILD_CREATE); } From patchwork Wed Nov 14 17:43:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10682959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92EB013BB for ; Wed, 14 Nov 2018 17:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856CC28ABB for ; Wed, 14 Nov 2018 17:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 734E02BD9E; Wed, 14 Nov 2018 17:44:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C36928ABB for ; Wed, 14 Nov 2018 17:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728249AbeKODsK (ORCPT ); Wed, 14 Nov 2018 22:48:10 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43165 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbeKODsK (ORCPT ); Wed, 14 Nov 2018 22:48:10 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10so727028wrs.10 for ; Wed, 14 Nov 2018 09:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aLZlhqPQeOMoKZNGV92nfAyysfuaZdsP1aaQfDpApiM=; b=oJddccpsunU6/H3PAx9OWS0vY5iS0K4Awqb5PC9NFdpNt2wbGwxA+oppIGNsyjQpdc LSiwmfyzDzdXwDi9AgFeV6CKc+/bu5nQGq9i5GL/dqlltBQS4Z4ExFYn/DYvFgcuiAGj 7TlM109G6cZrHolxBvjlkBfhCoYHzarR6Liowp22dDqij906EER0dECukg2l9dasy3Wc eO9mq8MRmCVGAnO6B9hYVSoSK4dbezFlsdtT6Wkdgec7Pf7+Ez2rJSlSNhr8RwXPbdyT T27eCeawd8AxjR5/XFSEm6g8/n7Fbvf0vkO5YIpsSR9SOVU7ecnspOFa8aa/y2Ut+bgJ 7XFw== 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=aLZlhqPQeOMoKZNGV92nfAyysfuaZdsP1aaQfDpApiM=; b=kRASSwCsJwKky/1v38Hu6tyRYumQcFC9WoTMoJlhxPdJCvy/EHOajcIPeAvds1Uylx TO6YsVE43Aic2tm4D+G3vPsweCJtQIPD3fwHJ3N6RX+bVTuALOVqMhTRhX1RO5+1+UjX LLMAsLvAL2Pg1x93MPv5qwxKcIV6bwW/1sxrT6idiNjxFnd9yQSGSE2BhgmDRslRHJDY yHoxRPYh0NR9br6MzPNN2BvC6/cYczvmK2xEfDi8g+GnGQ6uXm7smgtX/KVsHbI3Ewum tvUzcky0EE1R7+y5B0fQ5CyCdTTOLhoydf3AfIk7lkdjhMKV+l725bYSNyXWWHQmtVXA BKPw== X-Gm-Message-State: AGRZ1gLT7MFDuno9tcpkKKq77cRviv+Ube9Rlc8PZIWVXhbZo8XRqL23 MS4mrV2E9d9XZ/SYPDdVipaG1ZSD X-Google-Smtp-Source: AJdET5eHgIL7QLeOFR+AC0nc3wP3MUfQon4098HPBPpikRIlUEV2xjMrUfdCyxNAC0K1WMJGPqtr8A== X-Received: by 2002:adf:b211:: with SMTP id u17-v6mr2716784wra.52.1542217440131; Wed, 14 Nov 2018 09:44:00 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id d18-v6sm8587887wre.25.2018.11.14.09.43.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:43:59 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 5/5] fsnotify: send event type FSNOTIFY_EVENT_DENTRY to super block mark Date: Wed, 14 Nov 2018 19:43:44 +0200 Message-Id: <20181114174344.17530-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114174344.17530-1-amir73il@gmail.com> References: <20181114174344.17530-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So far, existence of super block marks could be checked only on events with data type FSNOTIFY_EVENT_PATH. Use d_sb field of dentry from events with data type FSNOTIFY_EVENT_DENTRY to send event on super block mark. This change has no effect on current backends. Soon, this will allow fanotify backend to receive dentry events on a super block mark. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 6a120b7f8b94..c9d673f0cbdc 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -338,6 +338,9 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, mnt = real_mount(((const struct path *)data)->mnt); sb = mnt->mnt.mnt_sb; mnt_or_sb_mask = mnt->mnt_fsnotify_mask | sb->s_fsnotify_mask; + } else if (data_is == FSNOTIFY_EVENT_DENTRY) { + sb = ((const struct dentry *)data)->d_sb; + mnt_or_sb_mask = sb->s_fsnotify_mask; } /* An event "on child" is not intended for a mount/sb mark */ if (mask & FS_EVENT_ON_CHILD) @@ -350,8 +353,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, * SRCU because we have no references to any objects and do not * need SRCU to keep them "alive". */ - if (!to_tell->i_fsnotify_marks && - (!mnt || (!mnt->mnt_fsnotify_marks && !sb->s_fsnotify_marks))) + if (!to_tell->i_fsnotify_marks && (!mnt || !mnt->mnt_fsnotify_marks) && + (!sb || !sb->s_fsnotify_marks)) return 0; /* * if this is a modify event we may need to clear the ignored masks @@ -369,6 +372,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, if (mnt) { iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = fsnotify_first_mark(&mnt->mnt_fsnotify_marks); + } + if (sb) { iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = fsnotify_first_mark(&sb->s_fsnotify_marks); }