Skip to content

Commit 5835f33

Browse files
Miklos SzerediAl Viro
authored andcommitted
fuse: use d_materialise_unique()
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 6497d16 commit 5835f33

File tree

1 file changed

+26
-43
lines changed

1 file changed

+26
-43
lines changed

fs/fuse/dir.c

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,6 @@ int fuse_valid_type(int m)
267267
S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
268268
}
269269

270-
/*
271-
* Add a directory inode to a dentry, ensuring that no other dentry
272-
* refers to this inode. Called with fc->inst_mutex.
273-
*/
274-
static struct dentry *fuse_d_add_directory(struct dentry *entry,
275-
struct inode *inode)
276-
{
277-
struct dentry *alias = d_find_alias(inode);
278-
if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
279-
/* This tries to shrink the subtree below alias */
280-
fuse_invalidate_entry(alias);
281-
dput(alias);
282-
if (!hlist_empty(&inode->i_dentry))
283-
return ERR_PTR(-EBUSY);
284-
} else {
285-
dput(alias);
286-
}
287-
return d_splice_alias(inode, entry);
288-
}
289-
290270
int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
291271
struct fuse_entry_out *outarg, struct inode **inode)
292272
{
@@ -345,14 +325,31 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
345325
return err;
346326
}
347327

328+
static struct dentry *fuse_materialise_dentry(struct dentry *dentry,
329+
struct inode *inode)
330+
{
331+
struct dentry *newent;
332+
333+
if (inode && S_ISDIR(inode->i_mode)) {
334+
struct fuse_conn *fc = get_fuse_conn(inode);
335+
336+
mutex_lock(&fc->inst_mutex);
337+
newent = d_materialise_unique(dentry, inode);
338+
mutex_unlock(&fc->inst_mutex);
339+
} else {
340+
newent = d_materialise_unique(dentry, inode);
341+
}
342+
343+
return newent;
344+
}
345+
348346
static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
349347
unsigned int flags)
350348
{
351349
int err;
352350
struct fuse_entry_out outarg;
353351
struct inode *inode;
354352
struct dentry *newent;
355-
struct fuse_conn *fc = get_fuse_conn(dir);
356353
bool outarg_valid = true;
357354

358355
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,
368365
if (inode && get_node_id(inode) == FUSE_ROOT_ID)
369366
goto out_iput;
370367

371-
if (inode && S_ISDIR(inode->i_mode)) {
372-
mutex_lock(&fc->inst_mutex);
373-
newent = fuse_d_add_directory(entry, inode);
374-
mutex_unlock(&fc->inst_mutex);
375-
err = PTR_ERR(newent);
376-
if (IS_ERR(newent))
377-
goto out_iput;
378-
} else {
379-
newent = d_splice_alias(inode, entry);
380-
}
368+
newent = fuse_materialise_dentry(entry, inode);
369+
err = PTR_ERR(newent);
370+
if (IS_ERR(newent))
371+
goto out_err;
381372

382373
entry = newent ? newent : entry;
383374
if (outarg_valid)
@@ -1275,18 +1266,10 @@ static int fuse_direntplus_link(struct file *file,
12751266
if (!inode)
12761267
goto out;
12771268

1278-
if (S_ISDIR(inode->i_mode)) {
1279-
mutex_lock(&fc->inst_mutex);
1280-
alias = fuse_d_add_directory(dentry, inode);
1281-
mutex_unlock(&fc->inst_mutex);
1282-
err = PTR_ERR(alias);
1283-
if (IS_ERR(alias)) {
1284-
iput(inode);
1285-
goto out;
1286-
}
1287-
} else {
1288-
alias = d_splice_alias(inode, dentry);
1289-
}
1269+
alias = fuse_materialise_dentry(dentry, inode);
1270+
err = PTR_ERR(alias);
1271+
if (IS_ERR(alias))
1272+
goto out;
12901273

12911274
if (alias) {
12921275
dput(dentry);

0 commit comments

Comments
 (0)