From patchwork Tue Aug 6 14:30:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 2839431 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 935E4BF535 for ; Tue, 6 Aug 2013 14:31:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D299E201C8 for ; Tue, 6 Aug 2013 14:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 493DB201DA for ; Tue, 6 Aug 2013 14:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754780Ab3HFOaa (ORCPT ); Tue, 6 Aug 2013 10:30:30 -0400 Received: from mail-bk0-f48.google.com ([209.85.214.48]:55927 "EHLO mail-bk0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754798Ab3HFOaZ (ORCPT ); Tue, 6 Aug 2013 10:30:25 -0400 Received: by mail-bk0-f48.google.com with SMTP id jf20so183682bkc.7 for ; Tue, 06 Aug 2013 07:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zDkTGFSBpCKDgQjeInjkRRCypm/LHTtdknwC+7WIzQI=; b=Z8E20/WziKQqW8FAsAaViQs93uZrNiaQEUK6nb2IVYnuxp5tdpz/7pUiVGecEqBZJL zPNApW6lHIIpN+NkaYOjuj9JoOWl2PQn+h7bycavRIjSgLAWZJHad6O/BVUclq8RVo8E Zl1xGowlR3stG9ndkRGwcYT7EbiJ9Khcq8vds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zDkTGFSBpCKDgQjeInjkRRCypm/LHTtdknwC+7WIzQI=; b=Or+NZ4upu3YePOWkKO4QPH3Z7b2nqRns8v40fzp/9APNxZ5dvKkPrCOuFbS3hcv1CY h0XomtAPm8noWNiGLvSKr8zhoFJ2oRDVBp2DMzOXTrkJSWklzBtKQVsHxciNC6W7cARP vjr9ZJtc7omQJ3s3gtwdZwTYFsOYj5rte2faHzXT0l7WHT/OzGn6uE5v4iVgmTfP4C+R yk2C97eq9ljb5CbikaQuR2A3tXXuSelTcg8Iob4dHMvq4YCf21DWTxPgPRXqk89ZNGnI bOOaR3Kxx++bzmL/c0NDZ/aRuqYCGd7YMI1AnVB6ecDM28yLuyaUyjLIA078mr2jndsa STKQ== X-Gm-Message-State: ALoCoQlsCSFdepftIIszGZ98sS5u1KMkkVoek+2/AwMEot2BT0z+UCchC9kWlAboan0x7hNoeuMH X-Received: by 10.204.56.135 with SMTP id y7mr407644bkg.90.1375799423950; Tue, 06 Aug 2013 07:30:23 -0700 (PDT) Received: from tucsk.pomaz.szeredi.hu (563BF5AA.catv.pool.telekom.hu. [86.59.245.170]) by mx.google.com with ESMTPSA id oe7sm726001bkb.5.2013.08.06.07.30.22 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 Aug 2013 07:30:23 -0700 (PDT) From: Miklos Szeredi To: rwheeler@redhat.com, avati@redhat.com, viro@ZenIV.linux.org.uk Cc: bfoster@redhat.com, dhowells@redhat.com, eparis@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Trond.Myklebust@netapp.com, swhiteho@redhat.com, mszeredi@suse.cz Subject: [PATCH 3/4] fuse: use d_materialise_unique() Date: Tue, 6 Aug 2013 16:30:02 +0200 Message-Id: <1375799403-28544-4-git-send-email-miklos@szeredi.hu> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1375799403-28544-1-git-send-email-miklos@szeredi.hu> References: <1375799403-28544-1-git-send-email-miklos@szeredi.hu> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, KHOP_BIG_TO_CC,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miklos Szeredi Use d_materialise_unique() instead of d_splice_alias(). This allows dentry subtrees to be moved to a new place if there moved, even if something is referencing a dentry in the subtree (open fd, cwd, etc..). This will also allow us to drop a subtree if it is found to be replaced by something else. In this case the disconnected subtree can later be reconnected to its new location. d_materialise_unique() ensures that a directory entry only ever has one alias. We keep fc->inst_mutex around the calls for d_materialise_unique() on directories to prevent a race with mkdir "stealing" the inode. Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 69 ++++++++++++++++++++++------------------------------------- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 72a5d5b..131d14b 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -267,26 +267,6 @@ int fuse_valid_type(int m) S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); } -/* - * Add a directory inode to a dentry, ensuring that no other dentry - * refers to this inode. Called with fc->inst_mutex. - */ -static struct dentry *fuse_d_add_directory(struct dentry *entry, - struct inode *inode) -{ - struct dentry *alias = d_find_alias(inode); - if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) { - /* This tries to shrink the subtree below alias */ - fuse_invalidate_entry(alias); - dput(alias); - if (!hlist_empty(&inode->i_dentry)) - return ERR_PTR(-EBUSY); - } else { - dput(alias); - } - return d_splice_alias(inode, entry); -} - int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name, struct fuse_entry_out *outarg, struct inode **inode) { @@ -345,6 +325,24 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name, return err; } +static struct dentry *fuse_materialise_dentry(struct dentry *dentry, + struct inode *inode) +{ + struct dentry *newent; + + if (inode && S_ISDIR(inode->i_mode)) { + struct fuse_conn *fc = get_fuse_conn(inode); + + mutex_lock(&fc->inst_mutex); + newent = d_materialise_unique(dentry, inode); + mutex_unlock(&fc->inst_mutex); + } else { + newent = d_materialise_unique(dentry, inode); + } + + return newent; +} + static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, unsigned int flags) { @@ -352,7 +350,6 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, struct fuse_entry_out outarg; struct inode *inode; struct dentry *newent; - struct fuse_conn *fc = get_fuse_conn(dir); bool outarg_valid = true; err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name, @@ -368,16 +365,10 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, if (inode && get_node_id(inode) == FUSE_ROOT_ID) goto out_iput; - if (inode && S_ISDIR(inode->i_mode)) { - mutex_lock(&fc->inst_mutex); - newent = fuse_d_add_directory(entry, inode); - mutex_unlock(&fc->inst_mutex); - err = PTR_ERR(newent); - if (IS_ERR(newent)) - goto out_iput; - } else { - newent = d_splice_alias(inode, entry); - } + newent = fuse_materialise_dentry(entry, inode); + err = PTR_ERR(newent); + if (IS_ERR(newent)) + goto out_err; entry = newent ? newent : entry; if (outarg_valid) @@ -1275,18 +1266,10 @@ static int fuse_direntplus_link(struct file *file, if (!inode) goto out; - if (S_ISDIR(inode->i_mode)) { - mutex_lock(&fc->inst_mutex); - alias = fuse_d_add_directory(dentry, inode); - mutex_unlock(&fc->inst_mutex); - err = PTR_ERR(alias); - if (IS_ERR(alias)) { - iput(inode); - goto out; - } - } else { - alias = d_splice_alias(inode, dentry); - } + alias = fuse_materialise_dentry(dentry, inode); + err = PTR_ERR(alias); + if (IS_ERR(alias)) + goto out; if (alias) { dput(dentry);