Skip to content

Commit 91dee39

Browse files
committed
ceph: fix snap realm splits
The snap realm split was checking i_snap_realm, not the list_head, to determine if an inode belonged in the new realm. The check always failed, which meant we always moved the inode, corrupting the old realm's list and causing various crashes. Also wait to release old realm reference to avoid possibility of use after free. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent c10f5e1 commit 91dee39

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

‎fs/ceph/snap.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,20 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
869869
continue;
870870
ci = ceph_inode(inode);
871871
spin_lock(&inode->i_lock);
872-
if (!ci->i_snap_realm)
873-
goto split_skip_inode;
874-
ceph_put_snap_realm(mdsc, ci->i_snap_realm);
875-
spin_lock(&realm->inodes_with_caps_lock);
876-
list_add(&ci->i_snap_realm_item,
877-
&realm->inodes_with_caps);
878-
ci->i_snap_realm = realm;
879-
spin_unlock(&realm->inodes_with_caps_lock);
880-
ceph_get_snap_realm(mdsc, realm);
881-
split_skip_inode:
872+
if (list_empty(&ci->i_snap_realm_item)) {
873+
struct ceph_snap_realm *oldrealm =
874+
ci->i_snap_realm;
875+
876+
dout(" moving %p to split realm %llx %p\n",
877+
inode, realm->ino, realm);
878+
spin_lock(&realm->inodes_with_caps_lock);
879+
list_add(&ci->i_snap_realm_item,
880+
&realm->inodes_with_caps);
881+
ci->i_snap_realm = realm;
882+
spin_unlock(&realm->inodes_with_caps_lock);
883+
ceph_get_snap_realm(mdsc, realm);
884+
ceph_put_snap_realm(mdsc, oldrealm);
885+
}
882886
spin_unlock(&inode->i_lock);
883887
iput(inode);
884888
}

0 commit comments

Comments
 (0)