Skip to content

Commit 2e58664

Browse files
lxbszidryomov
authored andcommitted
ceph: do not update snapshot context when there is no new snapshot
We will only track the uppest parent snapshot realm from which we need to rebuild the snapshot contexts _downward_ in hierarchy. For all the others having no new snapshot we will do nothing. This fix will avoid calling ceph_queue_cap_snap() on some inodes inappropriately. For example, with the code in mainline, suppose there are 2 directory hierarchies (with 6 directories total), like this: /dir_X1/dir_X2/dir_X3/ /dir_Y1/dir_Y2/dir_Y3/ Firstly, make a snapshot under /dir_X1/dir_X2/.snap/snap_X2, then make a root snapshot under /.snap/root_snap. Every time we make snapshots under /dir_Y1/..., the kclient will always try to rebuild the snap context for snap_X2 realm and finally will always try to queue cap snaps for dir_Y2 and dir_Y3, which makes no sense. That's because the snap_X2's seq is 2 and root_snap's seq is 3. So when creating a new snapshot under /dir_Y1/... the new seq will be 4, and the mds will send the kclient a snapshot backtrace in _downward_ order: seqs 4, 3. When ceph_update_snap_trace() is called, it will always rebuild the from the last realm, that's the root_snap. So later when rebuilding the snap context, the current logic will always cause it to rebuild the snap_X2 realm and then try to queue cap snaps for all the inodes related in that realm, even though it's not necessary. This is accompanied by a lot of these sorts of dout messages: "ceph: queue_cap_snap 00000000a42b796b nothing dirty|writing" Fix the logic to avoid this situation. Also, the 'invalidate' word is not precise here. In actuality, it will cause a rebuild of the existing snapshot contexts or just build non-existent ones. Rename it to 'rebuild_snapcs'. URL: https://tracker.ceph.com/issues/44100 Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 2941bf5 commit 2e58664

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

fs/ceph/snap.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,16 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
708708
__le64 *prior_parent_snaps; /* encoded */
709709
struct ceph_snap_realm *realm = NULL;
710710
struct ceph_snap_realm *first_realm = NULL;
711-
int invalidate = 0;
711+
struct ceph_snap_realm *realm_to_rebuild = NULL;
712+
int rebuild_snapcs;
712713
int err = -ENOMEM;
713714
LIST_HEAD(dirty_realms);
714715

715716
lockdep_assert_held_write(&mdsc->snap_rwsem);
716717

717718
dout("update_snap_trace deletion=%d\n", deletion);
718719
more:
720+
rebuild_snapcs = 0;
719721
ceph_decode_need(&p, e, sizeof(*ri), bad);
720722
ri = p;
721723
p += sizeof(*ri);
@@ -739,7 +741,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
739741
err = adjust_snap_realm_parent(mdsc, realm, le64_to_cpu(ri->parent));
740742
if (err < 0)
741743
goto fail;
742-
invalidate += err;
744+
rebuild_snapcs += err;
743745

744746
if (le64_to_cpu(ri->seq) > realm->seq) {
745747
dout("update_snap_trace updating %llx %p %lld -> %lld\n",
@@ -764,22 +766,30 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
764766
if (realm->seq > mdsc->last_snap_seq)
765767
mdsc->last_snap_seq = realm->seq;
766768

767-
invalidate = 1;
769+
rebuild_snapcs = 1;
768770
} else if (!realm->cached_context) {
769771
dout("update_snap_trace %llx %p seq %lld new\n",
770772
realm->ino, realm, realm->seq);
771-
invalidate = 1;
773+
rebuild_snapcs = 1;
772774
} else {
773775
dout("update_snap_trace %llx %p seq %lld unchanged\n",
774776
realm->ino, realm, realm->seq);
775777
}
776778

777-
dout("done with %llx %p, invalidated=%d, %p %p\n", realm->ino,
778-
realm, invalidate, p, e);
779+
dout("done with %llx %p, rebuild_snapcs=%d, %p %p\n", realm->ino,
780+
realm, rebuild_snapcs, p, e);
779781

780-
/* invalidate when we reach the _end_ (root) of the trace */
781-
if (invalidate && p >= e)
782-
rebuild_snap_realms(realm, &dirty_realms);
782+
/*
783+
* this will always track the uppest parent realm from which
784+
* we need to rebuild the snapshot contexts _downward_ in
785+
* hierarchy.
786+
*/
787+
if (rebuild_snapcs)
788+
realm_to_rebuild = realm;
789+
790+
/* rebuild_snapcs when we reach the _end_ (root) of the trace */
791+
if (realm_to_rebuild && p >= e)
792+
rebuild_snap_realms(realm_to_rebuild, &dirty_realms);
783793

784794
if (!first_realm)
785795
first_realm = realm;

0 commit comments

Comments
 (0)