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); } /*