From patchwork Thu Nov 10 22:44:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9422187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB9216022E for ; Thu, 10 Nov 2016 22:45:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED95729848 for ; Thu, 10 Nov 2016 22:45:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E26B529844; Thu, 10 Nov 2016 22:45:22 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 6BB3529844 for ; Thu, 10 Nov 2016 22:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756034AbcKJWpU (ORCPT ); Thu, 10 Nov 2016 17:45:20 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33115 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755961AbcKJWpS (ORCPT ); Thu, 10 Nov 2016 17:45:18 -0500 Received: by mail-wm0-f67.google.com with SMTP id u144so5863316wmu.0; Thu, 10 Nov 2016 14:45:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vM+i15yPmivjJpEj2kpzvMumA0jhmwYFIp1YiFoD9QM=; b=Ov2zU2eHEjDb5mBgm0L4xGmGHrdTZrhgyTSgVfhgDIjnE5z6lqiZ42aAD7rd95JMqq HW3bGpETs1shDPJcBDn+83GZkop6wCZTUFstHNYPr2QNuqy5/edIEe24Nz4ydk78J9sU LgatE/cgnbH3+RE8h/vm4A2msKsIe4sQ1JHPFXWmOy53tg573D88gxDfQeIEz++Ysdcj nC+tGjiDSw9FCDz+vkmiB1lg0k/YXc05hMg656tijNf4HTJQ5bOcNh/e5a33wtFj023f 5pUlrFcmjdnYYah/pKclo8Wr2pEPdBpZVBcvAkRHFTdxif+6AkAR8xyqJuFwFpTlPUef Xtng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vM+i15yPmivjJpEj2kpzvMumA0jhmwYFIp1YiFoD9QM=; b=VzoLRipUp9J4mqUpyUYCrnk34cbcxt4lOOPRHnV/cLiri1anzY8DMJ76NCnsVApUx+ OYsKCejq01SNCGX6okqLVZhTJoi6YyrPBzJz3vLQ9lSknbtJOP6HRNKNQEK1qGSyWqrJ FMoNAgp5C/CuTJAR/HVV8UHh41kWZMy76ha27EbC/Nu+3lVzuRnDJy+tlgj8t+mEYtUl eFbEktVG2pwEmSr066ysqxkLlaL08o/JSu9CUf0BbUBSYqpOebahLWIG+PaKhCVFABvw lENJl5tn0TmWXorVnNECmoMGknqUFp1iM+Y4FBUCYb0ubjKaSmQvJcx7eOiCaD51gl/w m21g== X-Gm-Message-State: ABUngvf/DkcfJv0uyjETEMuRNGGyG2TFeBWcEDTY+uQDoUtgEybozZhFgqpPHBHw8iuWiw== X-Received: by 10.194.47.203 with SMTP id f11mr6562978wjn.146.1478817913251; Thu, 10 Nov 2016 14:45:13 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-177-89-54.red.bezeqint.net. [79.177.89.54]) by smtp.gmail.com with ESMTPSA id n72sm15444310wmd.11.2016.11.10.14.45.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Nov 2016 14:45:12 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Konstantin Khlebnikov , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATH 1/4] vfs: reinterpret sillyrename flag as delete lock Date: Fri, 11 Nov 2016 00:44:40 +0200 Message-Id: <1478817883-27662-2-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478817883-27662-1-git-send-email-amir73il@gmail.com> References: <1478817883-27662-1-git-send-email-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 The dentry flag DCACHE_NFSFS_RENAMED indicates the the entry was sillyrenamed, as do some of the comment above may_delete(). It is better if the flag name indicates its true meaning instead of refering to nfs internal implementation. In fact, afs was using the flag with no relation to nfs silly rename. Re-brand the flag as DCACHE_DELETE_LOCK and modify places in the code that check/set it to use helpers cant_delete() and dont_delete(). The old flag DCACHE_NFSFS_RENAMED remains and is being used only in places really related to the nfs silly rename implementation. Signed-off-by: Amir Goldstein --- fs/afs/dir.c | 6 ++---- fs/btrfs/ioctl.c | 5 ++--- fs/namei.c | 5 ++--- include/linux/dcache.h | 13 +++++++++++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 51a241e..a0d79a7 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -678,9 +678,7 @@ static int afs_d_revalidate(struct dentry *dentry, unsigned int flags) /* the dirent, if it exists, now points to a different vnode */ not_found: - spin_lock(&dentry->d_lock); - dentry->d_flags |= DCACHE_NFSFS_RENAMED; - spin_unlock(&dentry->d_lock); + dont_delete(dentry); out_bad: _debug("dropping dentry %pd2", dentry); @@ -701,7 +699,7 @@ static int afs_d_delete(const struct dentry *dentry) { _enter("%pd", dentry); - if (dentry->d_flags & DCACHE_NFSFS_RENAMED) + if (cant_delete(dentry)) goto zap; if (d_really_is_positive(dentry) && diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7acbd2c..46048e54 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -785,8 +785,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, * 7. If we were asked to remove a directory and victim isn't one - ENOTDIR. * 8. If we were asked to remove a non-directory and victim isn't one - EISDIR. * 9. We can't remove a root or mountpoint. - * 10. We don't allow removal of NFS sillyrenamed files; it's handled by - * nfs_async_unlink(). + * 10. We don't allow removal of delete locked files. */ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir) @@ -816,7 +815,7 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir) return -EISDIR; if (IS_DEADDIR(dir)) return -ENOENT; - if (victim->d_flags & DCACHE_NFSFS_RENAMED) + if (cant_delete(victim)) return -EBUSY; return 0; } diff --git a/fs/namei.c b/fs/namei.c index 31d04d9..6040d1e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2762,8 +2762,7 @@ EXPORT_SYMBOL(__check_sticky); * 8. If we were asked to remove a directory and victim isn't one - ENOTDIR. * 9. If we were asked to remove a non-directory and victim isn't one - EISDIR. * 10. We can't remove a root or mountpoint. - * 11. We don't allow removal of NFS sillyrenamed files; it's handled by - * nfs_async_unlink(). + * 11. We don't allow removal of delete locked files. */ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir) { @@ -2795,7 +2794,7 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir) return -EISDIR; if (IS_DEADDIR(dir)) return -ENOENT; - if (victim->d_flags & DCACHE_NFSFS_RENAMED) + if (cant_delete(victim)) return -EBUSY; return 0; } diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 5beed7b..94cd40c 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -180,6 +180,7 @@ struct dentry_operations { #define DCACHE_OP_WEAK_REVALIDATE 0x00000800 #define DCACHE_NFSFS_RENAMED 0x00001000 +#define DCACHE_DELETE_LOCK 0x00001000 /* May not delete/rename */ /* this dentry has been "silly renamed" and has to be deleted on the last * dput() */ #define DCACHE_COOKIE 0x00002000 /* For use by dcookie subsystem */ @@ -350,6 +351,18 @@ static inline void dont_mount(struct dentry *dentry) spin_unlock(&dentry->d_lock); } +static inline int cant_delete(const struct dentry *dentry) +{ + return (dentry->d_flags & DCACHE_DELETE_LOCK); +} + +static inline void dont_delete(struct dentry *dentry) +{ + spin_lock(&dentry->d_lock); + dentry->d_flags |= DCACHE_DELETE_LOCK; + spin_unlock(&dentry->d_lock); +} + extern void __d_lookup_done(struct dentry *); static inline int d_in_lookup(struct dentry *dentry)