From patchwork Tue May 14 22:18:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10943989 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 35B7E924 for ; Tue, 14 May 2019 22:20:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2732C28978 for ; Tue, 14 May 2019 22:20:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 259E6289B1; Tue, 14 May 2019 22:20:34 +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 E704D289A1 for ; Tue, 14 May 2019 22:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbfENWTO (ORCPT ); Tue, 14 May 2019 18:19:14 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33591 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbfENWTO (ORCPT ); Tue, 14 May 2019 18:19:14 -0400 Received: by mail-wm1-f67.google.com with SMTP id c66so3326208wme.0 for ; Tue, 14 May 2019 15:19: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=jaoFftjx979q4SA6WjdVQTlTu4R2U03eLosOErcQnkY=; b=pvaM3KH5sH57Vh8gtpJz07FGxUSVZBzVB0mPfbtzQw8gwWYxJvZNC8QI17OrNocx7N I8jF9UEtzHpYAfW7oFatRcaKes3T0ysU+3wFsw2IjQeUQdw757cCuhznGdNyjmEbja9Y oppbpbraaATF/ZKfxKMV6w97SdMMpNlNSyIr5Z4VgEhE8wr5ecJjuIdLBlDR7fV+zhCL yRzfcNHBi7ahE9UbzF20UqcEA9eqBSBCG3TdTfyNpS5eFi+NbWZcUhsDPbUVBWsUkO5v ZSQnZH+xUEyfvCk5leRdhsWMysBqxXiUfnA2Ctt0WF3MEPuZB72BdQ/RJoIBs5EYgi8a VFMg== 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=jaoFftjx979q4SA6WjdVQTlTu4R2U03eLosOErcQnkY=; b=fcOca8DVytXjtUqphZMHOkZOPV/k2x9SVntqJycklLnfB8TTCdG5KLzcjgFuQWMLYl N6z3Eg9FTJS50J1Nz2xqvWn2Vds32r71MIwO+AqlDJnUIIottJEn132+zRY+q5aWZBdc LVld7QTtqiFVFX6moCZTu9Wx01Xf8DhmMORctesLv0py82FRoDOD61nPXGBRqnB1Rmtc GExjpuxLsTN+lsYFptNhcrxur+lsi2lprRO9BY6tCs1krUgA1jMutoXU9ZVaWvAXOGiU Z7QmLrU6ARQR7WUiYTxNDQcDow+P3LkMs1hVL4fOeilwrSjodBWialO8LbBkO6IgXgk+ tyxA== X-Gm-Message-State: APjAAAUMM9MdvWsBUn4T3ZVc6rAhQTEAbcMA5a/c+PyxUq0zq1CVKxE4 9sTIvmVbipcuBkw7o/73PEkTe0CV X-Google-Smtp-Source: APXvYqzf+VcIAaEDWMs5yCVwq1I2Dz8upG7VrHhKo9dDXQU6B+xozpW31wOH2R6fbciBd8TskuYoEg== X-Received: by 2002:a1c:f70c:: with SMTP id v12mr20266070wmh.86.1557872351939; Tue, 14 May 2019 15:19:11 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id h188sm423553wmf.48.2019.05.14.15.19.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 15:19:11 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Al Viro , linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH 1/4] fs: create simple_remove() helper Date: Wed, 15 May 2019 01:18:58 +0300 Message-Id: <20190514221901.29125-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514221901.29125-1-amir73il@gmail.com> References: <20190514221901.29125-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 There is a common pattern among pseudo filesystems for removing a dentry from code paths that are NOT coming from vfs_{unlink,rmdir}, using a combination of simple_{unlink,rmdir} and d_delete(). Create an helper to perform this common operation. This helper is going to be used as a place holder for the new fsnotify_remove() hook. Signed-off-by: Amir Goldstein --- fs/libfs.c | 22 ++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 23 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 4b59b1816efb..030e67c52b5f 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -353,6 +353,28 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry) } EXPORT_SYMBOL(simple_rmdir); +/* + * Unlike simple_unlink/rmdir, this helper is NOT called from vfs_unlink/rmdir. + * Caller must guaranty that d_parent and d_name are stable. + */ +int simple_remove(struct inode *dir, struct dentry *dentry) +{ + int ret; + + dget(dentry); + if (d_is_dir(dentry)) + ret = simple_rmdir(dir, dentry); + else + ret = simple_unlink(dir, dentry); + + if (!ret) + d_delete(dentry); + dput(dentry); + + return ret; +} +EXPORT_SYMBOL(simple_remove); + int simple_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) diff --git a/include/linux/fs.h b/include/linux/fs.h index f7fdfe93e25d..74ea5f0b3b9d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3245,6 +3245,7 @@ extern int simple_open(struct inode *inode, struct file *file); extern int simple_link(struct dentry *, struct inode *, struct dentry *); extern int simple_unlink(struct inode *, struct dentry *); extern int simple_rmdir(struct inode *, struct dentry *); +extern int simple_remove(struct inode *, struct dentry *); extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); extern int noop_fsync(struct file *, loff_t, loff_t, int); From patchwork Tue May 14 22:18:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10943921 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 552D8933 for ; Tue, 14 May 2019 22:19:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4566328821 for ; Tue, 14 May 2019 22:19:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A3828893; Tue, 14 May 2019 22:19:19 +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 CFC8828821 for ; Tue, 14 May 2019 22:19:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726911AbfENWTP (ORCPT ); Tue, 14 May 2019 18:19:15 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36255 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbfENWTP (ORCPT ); Tue, 14 May 2019 18:19:15 -0400 Received: by mail-wr1-f68.google.com with SMTP id s17so472757wru.3 for ; Tue, 14 May 2019 15:19: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=GVlogRg79Wqyr1hZWWSXcwzY7VWlV2o1M6WoAHCLED4=; b=c0a7CG91NaHEsAS1B28yPqeIc130Anvsi+y3Zn0jOQrEZPtPkRNMz4RysUZKvGqhMN D0p66+Xck0oqFmMYwR43WFgpNiqijgrB206AePuDSePpeqgKHxT66bj2bEmOzTxh8a5g rRdxO9cWSNkXa1y6UZS2SeHVwDXkzlVm0WAD/7+QinKDhxSeKSa4JsZ5aIq/e1teDLVV VTtgAyDal5EuhYsyS+SpujtKFtPBsupWshZTxHL600QwjYaX7Tk6DJNjTFXRi+7KqYwq 5GoeT10w+85cxw9Rtm7OVHHRD+o+ajZyBIWd51qhJHXmbLjrjbtClJUX18Klr831gGTr 3YUQ== 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=GVlogRg79Wqyr1hZWWSXcwzY7VWlV2o1M6WoAHCLED4=; b=YXB6gCPA3Ij2mI8hbISfomT4qu97aWxhAop1kZ68gQvZtMx0MSX/lOAH4HRCwn5EPj Lz50+8oz2p2Y7d9hBZZxuRQefjCL/2m4eBhzvJYbOLhAsbc+kkSgfU8rLgC/ffBvRa+y POcTp5eTxvTu6yQchryjT7XS2QEmBCaaDB31PyYHu40mQSNC+LwQzccP7cqeOBDfp2fs 9lqawfjt43BNmuZxnvbeBs6ycU5NziYzJbWIVcHMW0szxJ5iBEyxf7Dtardm3OHMQE6Q vbS/u0uvLocI8QJF3a8GOSs16uBSRJYMUQyyrTRwxsLCmRQ699NbIObXkv5d27yEUyIG 23oA== X-Gm-Message-State: APjAAAUevHXN2FcJyZjSwxINoajTIw+tO1vKQ950OmK030FuzfM9t5Dy AkWqryg3I38+9xLELAnXBHo= X-Google-Smtp-Source: APXvYqw8Eq1TWWuinP3vzYIvXxxUKOGhtUVFIAwJShUfFCRAtI9YeDpCRsp0Vo7dwj+WSULFvYc8rg== X-Received: by 2002:adf:ce88:: with SMTP id r8mr1841616wrn.191.1557872353319; Tue, 14 May 2019 15:19:13 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id h188sm423553wmf.48.2019.05.14.15.19.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 15:19:12 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Al Viro , linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH 2/4] fsnotify: add empty fsnotify_remove() hook Date: Wed, 15 May 2019 01:18:59 +0300 Message-Id: <20190514221901.29125-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514221901.29125-1-amir73il@gmail.com> References: <20190514221901.29125-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 We would like to move fsnotify_nameremove() calls from d_delete() into a higher layer where the hook makes more sense and so we can consider every d_delete() call site individually. Start by creating an empty hook called fsnotify_remove() and place it in the proper VFS call sites. After all d_delete() call sites will be converted to use the new hook, it will replace the old fsnotify_nameremove() hook in d_delete(). Signed-off-by: Amir Goldstein --- fs/libfs.c | 5 ++++- fs/namei.c | 2 ++ include/linux/fsnotify.h | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index 030e67c52b5f..0dd676fc9272 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -367,8 +368,10 @@ int simple_remove(struct inode *dir, struct dentry *dentry) else ret = simple_unlink(dir, dentry); - if (!ret) + if (!ret) { + fsnotify_remove(dir, dentry); d_delete(dentry); + } dput(dentry); return ret; diff --git a/fs/namei.c b/fs/namei.c index 20831c2fbb34..c9eda9cc5d43 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3883,6 +3883,7 @@ int vfs_rmdir(struct inode *dir, struct dentry *dentry) dentry->d_inode->i_flags |= S_DEAD; dont_mount(dentry); detach_mounts(dentry); + fsnotify_remove(dir, dentry); out: inode_unlock(dentry->d_inode); @@ -3999,6 +4000,7 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry, struct inode **delegate if (!error) { dont_mount(dentry); detach_mounts(dentry); + fsnotify_remove(dir, dentry); } } } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 94972e8eb6d1..455dff82595e 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -151,6 +151,19 @@ static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) __fsnotify_vfsmount_delete(mnt); } +/* + * fsnotify_remove - a filename was removed from a directory + * + * Caller must make sure that dentry->d_name is stable. + */ +static inline void fsnotify_remove(struct inode *dir, struct dentry *dentry) +{ + /* Expected to be called before d_delete() */ + WARN_ON_ONCE(d_is_negative(dentry)); + + /* TODO: call fsnotify_dirent() */ +} + /* * fsnotify_inoderemove - an inode is going away */ From patchwork Tue May 14 22:19:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10943927 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 DFFFB17EE for ; Tue, 14 May 2019 22:19:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFD0E28821 for ; Tue, 14 May 2019 22:19:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C41FC28852; Tue, 14 May 2019 22:19:21 +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 1D86828893 for ; Tue, 14 May 2019 22:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726924AbfENWTU (ORCPT ); Tue, 14 May 2019 18:19:20 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44906 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726908AbfENWTR (ORCPT ); Tue, 14 May 2019 18:19:17 -0400 Received: by mail-wr1-f67.google.com with SMTP id c5so426783wrs.11 for ; Tue, 14 May 2019 15:19:15 -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=lHvWPEdPz5M7DfRwzXnDIFqCatHT/VGerDKnxkatJLs=; b=WARQeUrm/NT+TkZelOgiWmqg+YGLpTlAMQ3NFnD7ht7ON0d6xY5k8UN/wZTCbrzQfk 3E3+8lHV6MTkvvdkECQZwQo5uMMiPsXvAej60qhos5sl/eX5LLe+RdPL8Jvez7/2j658 P/WHfbVUJf4ZJy+jyQGHXQtcN6zFeYcqa8OdFNbBSDXTklaJNiP0KCxLSfw+iQ8nGYTl K/MStvB3jWo5Nc6DGy8019POgxJdN8j72LKcYh1L1m4Jzg7I3LuFZ16iKkpAF69qgT/f h3RKvO6wME9o/WyOvY2ARe3t4xDotNLlEIeT56sWgjuJno9tMgquwjHEvWJQxnLMyIWJ tZSA== 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=lHvWPEdPz5M7DfRwzXnDIFqCatHT/VGerDKnxkatJLs=; b=KkBn7K2RllXfd5YPecQoc2TYrMU+9MM9yschhVqjPs5yJ+RmGmDqw3rlvDRkaiW4l0 XV335pdjPk+aSg4sNI0wo76t9JGZpmBZykv3pEVFrasO/MQAevdCxciPUGbHiB4Q6991 UUXDXWMZsgSB3yrqLuL2km27sItslWH/NXpCt7l/qRJu6LsxxnJRBkIkbR+FSzcVIhVe xBQs2VpbnqEvc2UF3zG6c87F5IFPlmXQSNEexPUu6aILgPpUzyJ7Wbs+h9+K4/3oIOqE FPRWKGT87wVG+81s9WrpyRLn0IPb/eHYuhqvMs+evlq1I1+7PguaDBMfjOAHKHokKNV4 Q1QA== X-Gm-Message-State: APjAAAUTlLqqKVAD1XjhWs7lD/ts5d84gJDYym+VjHyhsKdvqYXnqRVW LfwxFVEgelMzs1Yn3oKY+84= X-Google-Smtp-Source: APXvYqzeC7IK0k0ctAt3hzpTTxXVXPcz2RKRk6oje1eMjoFU73Xc2sfMqT3btYeaKPSi1hQy7hR9ug== X-Received: by 2002:adf:b243:: with SMTP id y3mr22539278wra.21.1557872354937; Tue, 14 May 2019 15:19:14 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id h188sm423553wmf.48.2019.05.14.15.19.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 15:19:14 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Al Viro , linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH 3/4] fs: convert filesystems to use simple_remove() helper Date: Wed, 15 May 2019 01:19:00 +0300 Message-Id: <20190514221901.29125-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514221901.29125-1-amir73il@gmail.com> References: <20190514221901.29125-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 Convert some filesystems to use the new simple_remove() helper. This will allow them to generate fsnotify delete events after the fsnotify_nameremove() hook is removed from d_delete(). Signed-off-by: Amir Goldstein --- arch/s390/hypfs/inode.c | 9 ++------- drivers/infiniband/hw/qib/qib_fs.c | 3 +-- fs/debugfs/inode.c | 20 ++++---------------- fs/tracefs/inode.c | 23 ++++------------------- net/sunrpc/rpc_pipe.c | 16 ++-------------- security/apparmor/apparmorfs.c | 6 +----- 6 files changed, 14 insertions(+), 63 deletions(-) diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c index ccad1398abd4..30a0ab967461 100644 --- a/arch/s390/hypfs/inode.c +++ b/arch/s390/hypfs/inode.c @@ -70,13 +70,8 @@ static void hypfs_remove(struct dentry *dentry) parent = dentry->d_parent; inode_lock(d_inode(parent)); - if (simple_positive(dentry)) { - if (d_is_dir(dentry)) - simple_rmdir(d_inode(parent), dentry); - else - simple_unlink(d_inode(parent), dentry); - } - d_delete(dentry); + if (simple_positive(dentry)) + simple_remove(d_inode(parent), dentry); dput(dentry); inode_unlock(d_inode(parent)); } diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c index ceb42d948412..795938a2488b 100644 --- a/drivers/infiniband/hw/qib/qib_fs.c +++ b/drivers/infiniband/hw/qib/qib_fs.c @@ -491,8 +491,7 @@ static int remove_device_files(struct super_block *sb, } remove_file(dir, "flash"); inode_unlock(d_inode(dir)); - ret = simple_rmdir(d_inode(root), dir); - d_delete(dir); + ret = simple_remove(d_inode(root), dir); dput(dir); bail: diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index acef14ad53db..bc96198df1d4 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -617,13 +617,10 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, } EXPORT_SYMBOL_GPL(debugfs_create_symlink); -static void __debugfs_remove_file(struct dentry *dentry, struct dentry *parent) +static void __debugfs_file_removed(struct dentry *dentry) { struct debugfs_fsdata *fsd; - simple_unlink(d_inode(parent), dentry); - d_delete(dentry); - /* * Paired with the closing smp_mb() implied by a successful * cmpxchg() in debugfs_file_get(): either @@ -643,18 +640,9 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent) int ret = 0; if (simple_positive(dentry)) { - dget(dentry); - if (!d_is_reg(dentry)) { - if (d_is_dir(dentry)) - ret = simple_rmdir(d_inode(parent), dentry); - else - simple_unlink(d_inode(parent), dentry); - if (!ret) - d_delete(dentry); - } else { - __debugfs_remove_file(dentry, parent); - } - dput(dentry); + ret = simple_remove(d_inode(parent), dentry); + if (d_is_reg(dentry)) + __debugfs_file_removed(dentry); } return ret; } diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7098c49f3693..6ac31ea9ad5d 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -501,25 +501,10 @@ __init struct dentry *tracefs_create_instance_dir(const char *name, static int __tracefs_remove(struct dentry *dentry, struct dentry *parent) { - int ret = 0; - - if (simple_positive(dentry)) { - if (dentry->d_inode) { - dget(dentry); - switch (dentry->d_inode->i_mode & S_IFMT) { - case S_IFDIR: - ret = simple_rmdir(parent->d_inode, dentry); - break; - default: - simple_unlink(parent->d_inode, dentry); - break; - } - if (!ret) - d_delete(dentry); - dput(dentry); - } - } - return ret; + if (simple_positive(dentry)) + return simple_remove(d_inode(parent), dentry); + + return 0; } /** diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index 979d23646e33..5b1a59776b9a 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -593,24 +593,12 @@ static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, static int __rpc_rmdir(struct inode *dir, struct dentry *dentry) { - int ret; - - dget(dentry); - ret = simple_rmdir(dir, dentry); - d_delete(dentry); - dput(dentry); - return ret; + return simple_remove(dir, dentry); } static int __rpc_unlink(struct inode *dir, struct dentry *dentry) { - int ret; - - dget(dentry); - ret = simple_unlink(dir, dentry); - d_delete(dentry); - dput(dentry); - return ret; + return simple_remove(dir, dentry); } static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 9ab5613fe07c..4a10acb4a6d3 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -351,11 +351,7 @@ static void aafs_remove(struct dentry *dentry) dir = d_inode(dentry->d_parent); inode_lock(dir); if (simple_positive(dentry)) { - if (d_is_dir(dentry)) - simple_rmdir(dir, dentry); - else - simple_unlink(dir, dentry); - d_delete(dentry); + simple_remove(dir, dentry); dput(dentry); } inode_unlock(dir); From patchwork Tue May 14 22:19:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10943999 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 5D7C917EE for ; Tue, 14 May 2019 22:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EDA728923 for ; Tue, 14 May 2019 22:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D74728987; Tue, 14 May 2019 22:20:35 +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 C4CB428965 for ; Tue, 14 May 2019 22:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726254AbfENWU0 (ORCPT ); Tue, 14 May 2019 18:20:26 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44908 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726597AbfENWTT (ORCPT ); Tue, 14 May 2019 18:19:19 -0400 Received: by mail-wr1-f67.google.com with SMTP id c5so426835wrs.11 for ; Tue, 14 May 2019 15:19: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=2BwTP2UXR2wpUVBza+34moJhMmiADl3xE9wV3LEwbVE=; b=GB8EgYcimUxTgqpYS4QKdpfWWv4UnIHa+X8vqhBrejIO4deeFR3ao75oZYwu10KLlu JN2t9+fHr8taE2J41tGDUm1RwxpGwpICdXbHWXY05h1otzNN5LoIBmbd+IH0IhQXJXlA VGuAYpCq6yk7UxF62i1RCezny+mJVonZwBwxYJ33gP2x4wbvdAPM63wjguMkD+OGa90b SCWu9lozXUc8j8JeVEcPHWW3d13oFxeSy6uwd+kZdaPZDIM9CR+XvpAEqip6Wg2sVdvi hNOz0xd0kieVzvW0e+BVcjmGPa2drq2tsW3PDu9xAwIiXoPO4MI1nuXt2hObLn/qs1tL omDg== 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=2BwTP2UXR2wpUVBza+34moJhMmiADl3xE9wV3LEwbVE=; b=sj2RrXi2Db5ZEpy/6KlAIh5uQ24IQjve4a862k+OeSr70F+Ne5q1FaIFyqMLdBafrY 79vfXilO3Bh/dOUt8cwG2ibLAKkg04ANvwsuEE/Z8vlg2nsCVN0b7+bIyx5l4waw2FvM XEMJpHD24iXcIGEQmJj7kZ+5uFzc4JMX2VMM/fkQh5UJ6nYmsPEVR4EL/cQQ3DDvvMgh 4KDvypI2piSj95vSXZAZOXCz2I1S84fRt3SYJQ/XwNGJREHPqhN446G5XJp6lg2yzYRq 0n8CeavKbwkZ/8grMmYMBY1T/x5hgCxHxYOIujiLPqOLgFaRFQyS/NFpY9cTJwPtD1vM 8o8A== X-Gm-Message-State: APjAAAWJ8U67xReWFN4b2ogxRF8J5a/2ULS7mkNw3KYUjIBxiDEAsjck Bnp4phRfZFqaKoSjx4fQ3IQ= X-Google-Smtp-Source: APXvYqwwL/Yck7SUL+/HsNbdrc2XxxtGcquj9fMy+bHGaOmwxiJmAgJi1XjM481f/V6vtNCxJ/ROiA== X-Received: by 2002:a5d:4e50:: with SMTP id r16mr12688862wrt.197.1557872356154; Tue, 14 May 2019 15:19:16 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.208]) by smtp.gmail.com with ESMTPSA id h188sm423553wmf.48.2019.05.14.15.19.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 15:19:15 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Al Viro , linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH 4/4] fsnotify: move fsnotify_nameremove() hook out of d_delete() Date: Wed, 15 May 2019 01:19:01 +0300 Message-Id: <20190514221901.29125-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514221901.29125-1-amir73il@gmail.com> References: <20190514221901.29125-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 d_delete() was piggy backed for the fsnotify_nameremove() hook when in fact not all callers of d_delete() care about fsnotify events. For all callers of d_delete() that may be interested in fsnotify events, we made sure that parent dir and d_name are stable and we call the fsnotify_remove() hook before calling d_delete(). Because of that, fsnotify_remove() does not need the safety measures that were in fsnotify_nameremove() to stabilize parent and name. Signed-off-by: Amir Goldstein --- fs/afs/dir_silly.c | 5 ---- fs/btrfs/ioctl.c | 4 +++- fs/configfs/dir.c | 3 +++ fs/dcache.c | 2 -- fs/devpts/inode.c | 1 + fs/nfs/unlink.c | 6 ----- fs/notify/fsnotify.c | 41 -------------------------------- include/linux/fsnotify.h | 7 +++++- include/linux/fsnotify_backend.h | 4 ---- 9 files changed, 13 insertions(+), 60 deletions(-) diff --git a/fs/afs/dir_silly.c b/fs/afs/dir_silly.c index f6f89fdab6b2..d3494825d08a 100644 --- a/fs/afs/dir_silly.c +++ b/fs/afs/dir_silly.c @@ -57,11 +57,6 @@ static int afs_do_silly_rename(struct afs_vnode *dvnode, struct afs_vnode *vnode if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) afs_edit_dir_add(dvnode, &new->d_name, &vnode->fid, afs_edit_dir_for_silly_1); - - /* vfs_unlink and the like do not issue this when a file is - * sillyrenamed, so do it here. - */ - fsnotify_nameremove(old, 0); } _leave(" = %d", ret); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 6dafa857bbb9..cd76e705d401 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2930,8 +2930,10 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, inode_lock(inode); err = btrfs_delete_subvolume(dir, dentry); inode_unlock(inode); - if (!err) + if (!err) { + fsnotify_remove(dir, dentry); d_delete(dentry); + } out_dput: dput(dentry); diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 591e82ba443c..78566002234a 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -27,6 +27,7 @@ #undef DEBUG #include +#include #include #include #include @@ -1797,6 +1798,7 @@ void configfs_unregister_group(struct config_group *group) configfs_detach_group(&group->cg_item); d_inode(dentry)->i_flags |= S_DEAD; dont_mount(dentry); + fsnotify_remove(d_inode(parent), dentry); d_delete(dentry); inode_unlock(d_inode(parent)); @@ -1925,6 +1927,7 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys) configfs_detach_group(&group->cg_item); d_inode(dentry)->i_flags |= S_DEAD; dont_mount(dentry); + fsnotify_remove(d_inode(root), dentry); inode_unlock(d_inode(dentry)); d_delete(dentry); diff --git a/fs/dcache.c b/fs/dcache.c index 8136bda27a1f..ce131339410c 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2371,7 +2371,6 @@ EXPORT_SYMBOL(d_hash_and_lookup); void d_delete(struct dentry * dentry) { struct inode *inode = dentry->d_inode; - int isdir = d_is_dir(dentry); spin_lock(&inode->i_lock); spin_lock(&dentry->d_lock); @@ -2386,7 +2385,6 @@ void d_delete(struct dentry * dentry) spin_unlock(&dentry->d_lock); spin_unlock(&inode->i_lock); } - fsnotify_nameremove(dentry, isdir); } EXPORT_SYMBOL(d_delete); diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 553a3f3300ae..aea8dda154e2 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -624,6 +624,7 @@ void devpts_pty_kill(struct dentry *dentry) dentry->d_fsdata = NULL; drop_nlink(dentry->d_inode); + fsnotify_remove(d_inode(dentry->d_parent), dentry); d_delete(dentry); dput(dentry); /* d_alloc_name() in devpts_pty_new() */ } diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c index 52d533967485..0effeee28352 100644 --- a/fs/nfs/unlink.c +++ b/fs/nfs/unlink.c @@ -396,12 +396,6 @@ nfs_complete_sillyrename(struct rpc_task *task, struct nfs_renamedata *data) nfs_cancel_async_unlink(dentry); return; } - - /* - * vfs_unlink and the like do not issue this when a file is - * sillyrenamed, so do it here. - */ - fsnotify_nameremove(dentry, 0); } #define SILLYNAME_PREFIX ".nfs" diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 8c7cbac7183c..5433e37fb0c5 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -107,47 +107,6 @@ void fsnotify_sb_delete(struct super_block *sb) fsnotify_clear_marks_by_sb(sb); } -/* - * fsnotify_nameremove - a filename was removed from a directory - * - * This is mostly called under parent vfs inode lock so name and - * dentry->d_parent should be stable. However there are some corner cases where - * inode lock is not held. So to be on the safe side and be reselient to future - * callers and out of tree users of d_delete(), we do not assume that d_parent - * and d_name are stable and we use dget_parent() and - * take_dentry_name_snapshot() to grab stable references. - */ -void fsnotify_nameremove(struct dentry *dentry, int isdir) -{ - struct dentry *parent; - struct name_snapshot name; - __u32 mask = FS_DELETE; - - /* d_delete() of pseudo inode? (e.g. __ns_get_path() playing tricks) */ - if (IS_ROOT(dentry)) - return; - - if (isdir) - mask |= FS_ISDIR; - - parent = dget_parent(dentry); - /* Avoid unneeded take_dentry_name_snapshot() */ - if (!(d_inode(parent)->i_fsnotify_mask & FS_DELETE) && - !(dentry->d_sb->s_fsnotify_mask & FS_DELETE)) - goto out_dput; - - take_dentry_name_snapshot(&name, dentry); - - fsnotify(d_inode(parent), mask, d_inode(dentry), FSNOTIFY_EVENT_INODE, - &name.name, 0); - - release_dentry_name_snapshot(&name); - -out_dput: - dput(parent); -} -EXPORT_SYMBOL(fsnotify_nameremove); - /* * Given an inode, first check if we care what happens to our children. Inotify * and dnotify both tell their parents about events. If we care about any event diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 455dff82595e..7f68cb9825dd 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -158,10 +158,15 @@ static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) */ static inline void fsnotify_remove(struct inode *dir, struct dentry *dentry) { + __u32 mask = FS_DELETE; + /* Expected to be called before d_delete() */ WARN_ON_ONCE(d_is_negative(dentry)); - /* TODO: call fsnotify_dirent() */ + if (d_is_dir(dentry)) + mask |= FS_ISDIR; + + fsnotify_dirent(dir, dentry, mask); } /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index a9f9dcc1e515..c28f6ed1f59b 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -355,7 +355,6 @@ extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u extern void __fsnotify_inode_delete(struct inode *inode); extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); extern void fsnotify_sb_delete(struct super_block *sb); -extern void fsnotify_nameremove(struct dentry *dentry, int isdir); extern u32 fsnotify_get_cookie(void); static inline int fsnotify_inode_watches_children(struct inode *inode) @@ -525,9 +524,6 @@ static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt) static inline void fsnotify_sb_delete(struct super_block *sb) {} -static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) -{} - static inline void fsnotify_update_flags(struct dentry *dentry) {}