Skip to content

Commit 825978f

Browse files
lxbszidryomov
authored andcommitted
ceph: fix possible deadlock when holding Fwb to get inline_data
1, mount with wsync. 2, create a file with O_RDWR, and the request was sent to mds.0: ceph_atomic_open()--> ceph_mdsc_do_request(openc) finish_open(file, dentry, ceph_open)--> ceph_open()--> ceph_init_file()--> ceph_init_file_info()--> ceph_uninline_data()--> { ... if (inline_version == 1 || /* initial version, no data */ inline_version == CEPH_INLINE_NONE) goto out_unlock; ... } The inline_version will be 1, which is the initial version for the new create file. And here the ci->i_inline_version will keep with 1, it's buggy. 3, buffer write to the file immediately: ceph_write_iter()--> ceph_get_caps(file, need=Fw, want=Fb, ...); generic_perform_write()--> a_ops->write_begin()--> ceph_write_begin()--> netfs_write_begin()--> netfs_begin_read()--> netfs_rreq_submit_slice()--> netfs_read_from_server()--> rreq->netfs_ops->issue_read()--> ceph_netfs_issue_read()--> { ... if (ci->i_inline_version != CEPH_INLINE_NONE && ceph_netfs_issue_op_inline(subreq)) return; ... } ceph_put_cap_refs(ci, Fwb); The ceph_netfs_issue_op_inline() will send a getattr(Fsr) request to mds.1. 4, then the mds.1 will request the rd lock for CInode::filelock from the auth mds.0, the mds.0 will do the CInode::filelock state transation from excl --> sync, but it need to revoke the Fxwb caps back from the clients. While the kernel client has aleady held the Fwb caps and waiting for the getattr(Fsr). It's deadlock! URL: https://tracker.ceph.com/issues/55377 Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 3459bd0 commit 825978f

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

fs/ceph/addr.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,18 +1648,31 @@ int ceph_uninline_data(struct file *file)
16481648
struct inode *inode = file_inode(file);
16491649
struct ceph_inode_info *ci = ceph_inode(inode);
16501650
struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
1651-
struct ceph_osd_request *req;
1651+
struct ceph_osd_request *req = NULL;
16521652
struct ceph_cap_flush *prealloc_cf;
16531653
struct folio *folio = NULL;
16541654
u64 inline_version = CEPH_INLINE_NONE;
16551655
struct page *pages[1];
16561656
int err = 0;
16571657
u64 len;
16581658

1659+
spin_lock(&ci->i_ceph_lock);
1660+
inline_version = ci->i_inline_version;
1661+
spin_unlock(&ci->i_ceph_lock);
1662+
1663+
dout("uninline_data %p %llx.%llx inline_version %llu\n",
1664+
inode, ceph_vinop(inode), inline_version);
1665+
1666+
if (inline_version == CEPH_INLINE_NONE)
1667+
return 0;
1668+
16591669
prealloc_cf = ceph_alloc_cap_flush();
16601670
if (!prealloc_cf)
16611671
return -ENOMEM;
16621672

1673+
if (inline_version == 1) /* initial version, no data */
1674+
goto out_uninline;
1675+
16631676
folio = read_mapping_folio(inode->i_mapping, 0, file);
16641677
if (IS_ERR(folio)) {
16651678
err = PTR_ERR(folio);
@@ -1668,17 +1681,6 @@ int ceph_uninline_data(struct file *file)
16681681

16691682
folio_lock(folio);
16701683

1671-
spin_lock(&ci->i_ceph_lock);
1672-
inline_version = ci->i_inline_version;
1673-
spin_unlock(&ci->i_ceph_lock);
1674-
1675-
dout("uninline_data %p %llx.%llx inline_version %llu\n",
1676-
inode, ceph_vinop(inode), inline_version);
1677-
1678-
if (inline_version == 1 || /* initial version, no data */
1679-
inline_version == CEPH_INLINE_NONE)
1680-
goto out_unlock;
1681-
16821684
len = i_size_read(inode);
16831685
if (len > folio_size(folio))
16841686
len = folio_size(folio);
@@ -1743,6 +1745,7 @@ int ceph_uninline_data(struct file *file)
17431745
ceph_update_write_metrics(&fsc->mdsc->metric, req->r_start_latency,
17441746
req->r_end_latency, len, err);
17451747

1748+
out_uninline:
17461749
if (!err) {
17471750
int dirty;
17481751

@@ -1761,8 +1764,10 @@ int ceph_uninline_data(struct file *file)
17611764
if (err == -ECANCELED)
17621765
err = 0;
17631766
out_unlock:
1764-
folio_unlock(folio);
1765-
folio_put(folio);
1767+
if (folio) {
1768+
folio_unlock(folio);
1769+
folio_put(folio);
1770+
}
17661771
out:
17671772
ceph_free_cap_flush(prealloc_cf);
17681773
dout("uninline_data %p %llx.%llx inline_version %llu = %d\n",

0 commit comments

Comments
 (0)