Skip to content

Commit 1b2ba3c

Browse files
lxbszidryomov
authored andcommitted
ceph: flush the mdlog for filesystem sync
Before waiting for a request's safe reply, we will send the mdlog flush request to the relevant MDS. And this will also flush the mdlog for all the other unsafe requests in the same session, so we can record the last session and no need to flush mdlog again in the next loop. But there still have cases that it may send the mdlog flush requst twice or more, but that should be not often. Rename wait_unsafe_requests() to flush_mdlog_and_wait_mdsc_unsafe_requests() to make it more descriptive. [xiubli: fold in MDS request refcount leak fix from Jeff] URL: https://tracker.ceph.com/issues/55284 URL: https://tracker.ceph.com/issues/55411 Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent ae06706 commit 1b2ba3c

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

fs/ceph/mds_client.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,15 +4740,17 @@ void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
47404740
}
47414741

47424742
/*
4743-
* wait for all write mds requests to flush.
4743+
* flush the mdlog and wait for all write mds requests to flush.
47444744
*/
4745-
static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid)
4745+
static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
4746+
u64 want_tid)
47464747
{
47474748
struct ceph_mds_request *req = NULL, *nextreq;
4749+
struct ceph_mds_session *last_session = NULL;
47484750
struct rb_node *n;
47494751

47504752
mutex_lock(&mdsc->mutex);
4751-
dout("wait_unsafe_requests want %lld\n", want_tid);
4753+
dout("%s want %lld\n", __func__, want_tid);
47524754
restart:
47534755
req = __get_oldest_req(mdsc);
47544756
while (req && req->r_tid <= want_tid) {
@@ -4760,14 +4762,32 @@ static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid)
47604762
nextreq = NULL;
47614763
if (req->r_op != CEPH_MDS_OP_SETFILELOCK &&
47624764
(req->r_op & CEPH_MDS_OP_WRITE)) {
4765+
struct ceph_mds_session *s = req->r_session;
4766+
4767+
if (!s) {
4768+
req = nextreq;
4769+
continue;
4770+
}
4771+
47634772
/* write op */
47644773
ceph_mdsc_get_request(req);
47654774
if (nextreq)
47664775
ceph_mdsc_get_request(nextreq);
4776+
s = ceph_get_mds_session(s);
47674777
mutex_unlock(&mdsc->mutex);
4768-
dout("wait_unsafe_requests wait on %llu (want %llu)\n",
4778+
4779+
/* send flush mdlog request to MDS */
4780+
if (last_session != s) {
4781+
send_flush_mdlog(s);
4782+
ceph_put_mds_session(last_session);
4783+
last_session = s;
4784+
} else {
4785+
ceph_put_mds_session(s);
4786+
}
4787+
dout("%s wait on %llu (want %llu)\n", __func__,
47694788
req->r_tid, want_tid);
47704789
wait_for_completion(&req->r_safe_completion);
4790+
47714791
mutex_lock(&mdsc->mutex);
47724792
ceph_mdsc_put_request(req);
47734793
if (!nextreq)
@@ -4782,7 +4802,8 @@ static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid)
47824802
req = nextreq;
47834803
}
47844804
mutex_unlock(&mdsc->mutex);
4785-
dout("wait_unsafe_requests done\n");
4805+
ceph_put_mds_session(last_session);
4806+
dout("%s done\n", __func__);
47864807
}
47874808

47884809
void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
@@ -4811,7 +4832,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
48114832
dout("sync want tid %lld flush_seq %lld\n",
48124833
want_tid, want_flush);
48134834

4814-
wait_unsafe_requests(mdsc, want_tid);
4835+
flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
48154836
wait_caps_flush(mdsc, want_flush);
48164837
}
48174838

0 commit comments

Comments
 (0)