Unverified Commit 10361bdc authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!10928 libceph: fix race between delayed_work() and ceph_monc_stop()

parents 9560420d 21ccf848
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -1014,13 +1014,19 @@ static void delayed_work(struct work_struct *work)
	struct ceph_mon_client *monc =
		container_of(work, struct ceph_mon_client, delayed_work.work);

	dout("monc delayed_work\n");
	mutex_lock(&monc->mutex);
	dout("%s mon%d\n", __func__, monc->cur_mon);
	if (monc->cur_mon < 0) {
		goto out;
	}

	if (monc->hunting) {
		dout("%s continuing hunt\n", __func__);
		reopen_session(monc);
	} else {
		int is_auth = ceph_auth_is_authenticated(monc->auth);

		dout("%s is_authed %d\n", __func__, is_auth);
		if (ceph_con_keepalive_expired(&monc->con,
					       CEPH_MONC_PING_TIMEOUT)) {
			dout("monc keepalive timeout\n");
@@ -1045,6 +1051,8 @@ static void delayed_work(struct work_struct *work)
		}
	}
	__schedule_delayed(monc);

out:
	mutex_unlock(&monc->mutex);
}

@@ -1157,13 +1165,15 @@ EXPORT_SYMBOL(ceph_monc_init);
void ceph_monc_stop(struct ceph_mon_client *monc)
{
	dout("stop\n");
	cancel_delayed_work_sync(&monc->delayed_work);

	mutex_lock(&monc->mutex);
	__close_session(monc);
	monc->hunting = false;
	monc->cur_mon = -1;
	mutex_unlock(&monc->mutex);

	cancel_delayed_work_sync(&monc->delayed_work);

	/*
	 * flush msgr queue before we destroy ourselves to ensure that:
	 *  - any work that references our embedded con is finished.