Unverified Commit 36fe9923 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

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

parents b5baed0e ed4d316a
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -963,13 +963,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");
@@ -994,6 +1000,8 @@ static void delayed_work(struct work_struct *work)
		}
	}
	__schedule_delayed(monc);

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

@@ -1106,13 +1114,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.