Skip to content

Commit f69999b

Browse files
committed
Revert " fs/9p: mitigate inode collisions"
This reverts commit d05dcfd. This is a requirement to revert commit 724a084 ("fs/9p: simplify iget to remove unnecessary paths"), see that revert for details. Fixes: 724a084 ("fs/9p: simplify iget to remove unnecessary paths") Reported-by: Will Deacon <[email protected]> Link: https://lkml.kernel.org/r/20240923100508.GA32066@willie-the-truck Cc: [email protected] # v6.9+ Message-ID: <[email protected]> Signed-off-by: Dominique Martinet <[email protected]>
1 parent 42f7652 commit f69999b

File tree

4 files changed

+22
-56
lines changed

4 files changed

+22
-56
lines changed

fs/9p/v9fs.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,13 @@ extern int v9fs_vfs_rename(struct mnt_idmap *idmap,
179179
struct inode *old_dir, struct dentry *old_dentry,
180180
struct inode *new_dir, struct dentry *new_dentry,
181181
unsigned int flags);
182-
extern struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid,
183-
bool new);
182+
extern struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid);
184183
extern const struct inode_operations v9fs_dir_inode_operations_dotl;
185184
extern const struct inode_operations v9fs_file_inode_operations_dotl;
186185
extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
187186
extern const struct netfs_request_ops v9fs_req_ops;
188187
extern struct inode *v9fs_fid_iget_dotl(struct super_block *sb,
189-
struct p9_fid *fid, bool new);
188+
struct p9_fid *fid);
190189

191190
/* other default globals */
192191
#define V9FS_PORT 564
@@ -225,12 +224,12 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
225224
*/
226225
static inline struct inode *
227226
v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
228-
struct super_block *sb, bool new)
227+
struct super_block *sb)
229228
{
230229
if (v9fs_proto_dotl(v9ses))
231-
return v9fs_fid_iget_dotl(sb, fid, new);
230+
return v9fs_fid_iget_dotl(sb, fid);
232231
else
233-
return v9fs_fid_iget(sb, fid, new);
232+
return v9fs_fid_iget(sb, fid);
234233
}
235234

236235
#endif

fs/9p/vfs_inode.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ void v9fs_evict_inode(struct inode *inode)
366366
clear_inode(inode);
367367
}
368368

369-
struct inode *
370-
v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid, bool new)
369+
struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid)
371370
{
372371
dev_t rdev;
373372
int retval;
@@ -379,18 +378,8 @@ v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid, bool new)
379378
inode = iget_locked(sb, QID2INO(&fid->qid));
380379
if (unlikely(!inode))
381380
return ERR_PTR(-ENOMEM);
382-
if (!(inode->i_state & I_NEW)) {
383-
if (!new) {
384-
goto done;
385-
} else {
386-
p9_debug(P9_DEBUG_VFS, "WARNING: Inode collision %ld\n",
387-
inode->i_ino);
388-
iput(inode);
389-
remove_inode_hash(inode);
390-
inode = iget_locked(sb, QID2INO(&fid->qid));
391-
WARN_ON(!(inode->i_state & I_NEW));
392-
}
393-
}
381+
if (!(inode->i_state & I_NEW))
382+
return inode;
394383

395384
/*
396385
* initialize the inode with the stat info
@@ -414,11 +403,11 @@ v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid, bool new)
414403
v9fs_set_netfs_context(inode);
415404
v9fs_cache_inode_get_cookie(inode);
416405
unlock_new_inode(inode);
417-
done:
418406
return inode;
419407
error:
420408
iget_failed(inode);
421409
return ERR_PTR(retval);
410+
422411
}
423412

424413
/**
@@ -450,15 +439,8 @@ static int v9fs_at_to_dotl_flags(int flags)
450439
*/
451440
static void v9fs_dec_count(struct inode *inode)
452441
{
453-
if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2) {
454-
if (inode->i_nlink) {
455-
drop_nlink(inode);
456-
} else {
457-
p9_debug(P9_DEBUG_VFS,
458-
"WARNING: unexpected i_nlink zero %d inode %ld\n",
459-
inode->i_nlink, inode->i_ino);
460-
}
461-
}
442+
if (!S_ISDIR(inode->i_mode) || inode->i_nlink > 2)
443+
drop_nlink(inode);
462444
}
463445

464446
/**
@@ -509,9 +491,6 @@ static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags)
509491
} else
510492
v9fs_dec_count(inode);
511493

512-
if (inode->i_nlink <= 0) /* no more refs unhash it */
513-
remove_inode_hash(inode);
514-
515494
v9fs_invalidate_inode_attr(inode);
516495
v9fs_invalidate_inode_attr(dir);
517496

@@ -577,7 +556,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
577556
/*
578557
* instantiate inode and assign the unopened fid to the dentry
579558
*/
580-
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb, true);
559+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
581560
if (IS_ERR(inode)) {
582561
err = PTR_ERR(inode);
583562
p9_debug(P9_DEBUG_VFS,
@@ -706,7 +685,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
706685
else if (IS_ERR(fid))
707686
inode = ERR_CAST(fid);
708687
else
709-
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb, false);
688+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
710689
/*
711690
* If we had a rename on the server and a parallel lookup
712691
* for the new name, then make sure we instantiate with

fs/9p/vfs_inode_dotl.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ static kgid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
5252
return current_fsgid();
5353
}
5454

55-
56-
57-
struct inode *
58-
v9fs_fid_iget_dotl(struct super_block *sb, struct p9_fid *fid, bool new)
55+
struct inode *v9fs_fid_iget_dotl(struct super_block *sb, struct p9_fid *fid)
5956
{
6057
int retval;
6158
struct inode *inode;
@@ -65,18 +62,8 @@ v9fs_fid_iget_dotl(struct super_block *sb, struct p9_fid *fid, bool new)
6562
inode = iget_locked(sb, QID2INO(&fid->qid));
6663
if (unlikely(!inode))
6764
return ERR_PTR(-ENOMEM);
68-
if (!(inode->i_state & I_NEW)) {
69-
if (!new) {
70-
goto done;
71-
} else { /* deal with race condition in inode number reuse */
72-
p9_debug(P9_DEBUG_ERROR, "WARNING: Inode collision %lx\n",
73-
inode->i_ino);
74-
iput(inode);
75-
remove_inode_hash(inode);
76-
inode = iget_locked(sb, QID2INO(&fid->qid));
77-
WARN_ON(!(inode->i_state & I_NEW));
78-
}
79-
}
65+
if (!(inode->i_state & I_NEW))
66+
return inode;
8067

8168
/*
8269
* initialize the inode with the stat info
@@ -103,11 +90,12 @@ v9fs_fid_iget_dotl(struct super_block *sb, struct p9_fid *fid, bool new)
10390
goto error;
10491

10592
unlock_new_inode(inode);
106-
done:
93+
10794
return inode;
10895
error:
10996
iget_failed(inode);
11097
return ERR_PTR(retval);
98+
11199
}
112100

113101
struct dotl_openflag_map {
@@ -259,7 +247,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
259247
p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
260248
goto out;
261249
}
262-
inode = v9fs_fid_iget_dotl(dir->i_sb, fid, true);
250+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
263251
if (IS_ERR(inode)) {
264252
err = PTR_ERR(inode);
265253
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n", err);
@@ -352,7 +340,7 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
352340
}
353341

354342
/* instantiate inode and assign the unopened fid to the dentry */
355-
inode = v9fs_fid_iget_dotl(dir->i_sb, fid, true);
343+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
356344
if (IS_ERR(inode)) {
357345
err = PTR_ERR(inode);
358346
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",
@@ -788,7 +776,7 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
788776
err);
789777
goto error;
790778
}
791-
inode = v9fs_fid_iget_dotl(dir->i_sb, fid, true);
779+
inode = v9fs_fid_iget_dotl(dir->i_sb, fid);
792780
if (IS_ERR(inode)) {
793781
err = PTR_ERR(inode);
794782
p9_debug(P9_DEBUG_VFS, "inode creation failed %d\n",

fs/9p/vfs_super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
139139
else
140140
sb->s_d_op = &v9fs_dentry_operations;
141141

142-
inode = v9fs_get_inode_from_fid(v9ses, fid, sb, true);
142+
inode = v9fs_get_inode_from_fid(v9ses, fid, sb);
143143
if (IS_ERR(inode)) {
144144
retval = PTR_ERR(inode);
145145
goto release_sb;

0 commit comments

Comments
 (0)