Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp632222iog; Mon, 13 Jun 2022 09:31:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9pll1+zzRRPC2chv2zKrYZxCx3wZiDSt9dn8hXkTgW1c5URuyLVu3ifv47+BKpLDPsMYo X-Received: by 2002:a17:90a:c90d:b0:1e2:c96b:5337 with SMTP id v13-20020a17090ac90d00b001e2c96b5337mr16833760pjt.42.1655137894558; Mon, 13 Jun 2022 09:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137894; cv=none; d=google.com; s=arc-20160816; b=faW9g2Yaegn839tUJ1l4v8CUcExoBl9WmzjGQIJIZO+FJxmPyMOOLs+RIkHIccxnd+ ZBbgqhp5g9CuWdYFjbKrzf58c5mBd+8YhIwBVKuOQ+3TKgoNEbawD1+Gt6rXoOCDnP+Z KHvLC6//JTv7/VZnHAugCC+XrR7Uk8bYuxqeJh7Sk0u18VckHQ1+OVzITreArWG7ba6a u3k/ExfIE4DHPtCxQc6tF6mVRilllzu3lOj8MW8AvFMbrAn71ZXDfn/VCsIXmKNWma/q hdCxJCxQmnEXko+z42Od4Tk6VviTaxuejSow4lW/OZXtl0lxzsnPO6moLmNMpQwI2qdg WQYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=830hr82jlZDzuB+eNSNKxxUGNEXTsazXVpnab3xTqA0=; b=Z6pnNiDdZQiR/M+G6WNocE2eqwBo8RTpJmNHkdSHvElX09+22iuBi0IVDI0/k0Fg04 2xURRSbMFZRYpmtbDpp4ja3YfIx9HeEh0zZqNAYuvT5P2xr8yzdpQiBW1opBUlOs4ESs POEzo6qfPK5d1JsiHrBPGBMDh/kAHafU18/1VW3TS2gvD22ecDT8RTDHALrf3+W4pwQi nnlunCvQ+16BozMCIWHWqqJmafIQfzJptk645NTTM3lXgfExwF6EQlxomLXvr4qi86CX QVyL2NMXpeadsZyzCZiDLxemj2oSmJ1d8So9tuySGHsLMmLBr3ZhKjIrmuK9YmAhIWAM OLVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NaSovLv8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a17090a428a00b001e88d83b58esi12904909pjg.111.2022.06.13.09.31.22; Mon, 13 Jun 2022 09:31:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NaSovLv8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380466AbiFMOCU (ORCPT + 99 others); Mon, 13 Jun 2022 10:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380806AbiFMNzI (ORCPT ); Mon, 13 Jun 2022 09:55:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5055C8199B; Mon, 13 Jun 2022 04:35:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 115FC612D0; Mon, 13 Jun 2022 11:35:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E1C2C34114; Mon, 13 Jun 2022 11:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655120152; bh=IsJ3NMnoAFJ7wjN7A21WKBIHAnKxNuqqCDed6n0bc3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NaSovLv8v47duwjp3V0SffVX4uei+cxErNNmL7QtMVnt6kCK5Nszb4ohc0Z0VDrmh nSJoxpuBHZFKZKYbR0eczYt1sYg6Gx4NqRVlOEx/BSGZF9GmP9asO0gNOEJT1kNRq4 dVMc3I+0TWwgavKW6l1nGisVh4+TjJMbJ6/UCPx4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiubo Li , Jeff Layton , Ilya Dryomov , Sasha Levin Subject: [PATCH 5.18 261/339] ceph: flush the mdlog for filesystem sync Date: Mon, 13 Jun 2022 12:11:26 +0200 Message-Id: <20220613094934.568016028@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094926.497929857@linuxfoundation.org> References: <20220613094926.497929857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiubo Li [ Upstream commit 1b2ba3c5616e17ff951359e25c658a1c3f146f1e ] 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 Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/mds_client.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 1bd3e1bb0fdf..8c249511344d 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -4700,15 +4700,17 @@ void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) } /* - * wait for all write mds requests to flush. + * flush the mdlog and wait for all write mds requests to flush. */ -static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) +static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc, + u64 want_tid) { struct ceph_mds_request *req = NULL, *nextreq; + struct ceph_mds_session *last_session = NULL; struct rb_node *n; mutex_lock(&mdsc->mutex); - dout("wait_unsafe_requests want %lld\n", want_tid); + dout("%s want %lld\n", __func__, want_tid); restart: req = __get_oldest_req(mdsc); while (req && req->r_tid <= want_tid) { @@ -4720,14 +4722,32 @@ static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) nextreq = NULL; if (req->r_op != CEPH_MDS_OP_SETFILELOCK && (req->r_op & CEPH_MDS_OP_WRITE)) { + struct ceph_mds_session *s = req->r_session; + + if (!s) { + req = nextreq; + continue; + } + /* write op */ ceph_mdsc_get_request(req); if (nextreq) ceph_mdsc_get_request(nextreq); + s = ceph_get_mds_session(s); mutex_unlock(&mdsc->mutex); - dout("wait_unsafe_requests wait on %llu (want %llu)\n", + + /* send flush mdlog request to MDS */ + if (last_session != s) { + send_flush_mdlog(s); + ceph_put_mds_session(last_session); + last_session = s; + } else { + ceph_put_mds_session(s); + } + dout("%s wait on %llu (want %llu)\n", __func__, req->r_tid, want_tid); wait_for_completion(&req->r_safe_completion); + mutex_lock(&mdsc->mutex); ceph_mdsc_put_request(req); if (!nextreq) @@ -4742,7 +4762,8 @@ static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) req = nextreq; } mutex_unlock(&mdsc->mutex); - dout("wait_unsafe_requests done\n"); + ceph_put_mds_session(last_session); + dout("%s done\n", __func__); } void ceph_mdsc_sync(struct ceph_mds_client *mdsc) @@ -4771,7 +4792,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc) dout("sync want tid %lld flush_seq %lld\n", want_tid, want_flush); - wait_unsafe_requests(mdsc, want_tid); + flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid); wait_caps_flush(mdsc, want_flush); } -- 2.35.1