Skip to content

Commit 893e456

Browse files
jtlaytonidryomov
authored andcommitted
ceph: don't clear I_NEW until inode metadata is fully populated
Currently, we could have an open-by-handle (or NFS server) call into the filesystem and start working with an inode before it's properly filled out. Don't clear I_NEW until we have filled out the inode, and discard it properly if that fails. Note that we occasionally take an extra reference to the inode to ensure that we don't put the last reference in discard_new_inode, but rather leave it for ceph_async_iput. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent c4853e9 commit 893e456

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

‎fs/ceph/inode.c‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino)
5555
inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino);
5656
if (!inode)
5757
return ERR_PTR(-ENOMEM);
58-
if (inode->i_state & I_NEW) {
58+
if (inode->i_state & I_NEW)
5959
dout("get_inode created new inode %p %llx.%llx ino %llx\n",
6060
inode, ceph_vinop(inode), (u64)inode->i_ino);
61-
unlock_new_inode(inode);
62-
}
6361

6462
dout("get_inode on %lu=%llx.%llx got %p\n", inode->i_ino, vino.ino,
6563
vino.snap, inode);
@@ -88,6 +86,10 @@ struct inode *ceph_get_snapdir(struct inode *parent)
8886
inode->i_fop = &ceph_snapdir_fops;
8987
ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */
9088
ci->i_rbytes = 0;
89+
90+
if (inode->i_state & I_NEW)
91+
unlock_new_inode(inode);
92+
9193
return inode;
9294
}
9395

@@ -1304,7 +1306,6 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
13041306
err = PTR_ERR(in);
13051307
goto done;
13061308
}
1307-
req->r_target_inode = in;
13081309

13091310
err = fill_inode(in, req->r_locked_page, &rinfo->targeti, NULL,
13101311
session,
@@ -1314,8 +1315,13 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
13141315
if (err < 0) {
13151316
pr_err("fill_inode badness %p %llx.%llx\n",
13161317
in, ceph_vinop(in));
1318+
if (in->i_state & I_NEW)
1319+
discard_new_inode(in);
13171320
goto done;
13181321
}
1322+
req->r_target_inode = in;
1323+
if (in->i_state & I_NEW)
1324+
unlock_new_inode(in);
13191325
}
13201326

13211327
/*
@@ -1499,7 +1505,14 @@ static int readdir_prepopulate_inodes_only(struct ceph_mds_request *req,
14991505
if (rc < 0) {
15001506
pr_err("fill_inode badness on %p got %d\n", in, rc);
15011507
err = rc;
1508+
if (in->i_state & I_NEW) {
1509+
ihold(in);
1510+
discard_new_inode(in);
1511+
}
1512+
} else if (in->i_state & I_NEW) {
1513+
unlock_new_inode(in);
15021514
}
1515+
15031516
/* avoid calling iput_final() in mds dispatch threads */
15041517
ceph_async_iput(in);
15051518
}
@@ -1701,12 +1714,18 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
17011714
if (d_really_is_negative(dn)) {
17021715
/* avoid calling iput_final() in mds
17031716
* dispatch threads */
1717+
if (in->i_state & I_NEW) {
1718+
ihold(in);
1719+
discard_new_inode(in);
1720+
}
17041721
ceph_async_iput(in);
17051722
}
17061723
d_drop(dn);
17071724
err = ret;
17081725
goto next_item;
17091726
}
1727+
if (in->i_state & I_NEW)
1728+
unlock_new_inode(in);
17101729

17111730
if (d_really_is_negative(dn)) {
17121731
if (ceph_security_xattr_deadlock(in)) {

0 commit comments

Comments
 (0)