From patchwork Fri Aug 25 13:54:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13365932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81221C71133 for ; Fri, 25 Aug 2023 14:06:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DA2A680008; Fri, 25 Aug 2023 10:06:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A8B680001; Fri, 25 Aug 2023 10:06:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05265680008; Fri, 25 Aug 2023 10:06:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EAAB3680001 for ; Fri, 25 Aug 2023 10:06:11 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A765E80702 for ; Fri, 25 Aug 2023 14:06:11 +0000 (UTC) X-FDA: 81162801342.09.E8D1BB1 Received: from out-247.mta1.migadu.com (out-247.mta1.migadu.com [95.215.58.247]) by imf14.hostedemail.com (Postfix) with ESMTP id 96D83100034 for ; Fri, 25 Aug 2023 14:06:09 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="IDkI/8Fc"; spf=pass (imf14.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.247 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692972369; a=rsa-sha256; cv=none; b=pa1Xgg47MwNm1qi/3nOHOGZOgzshcWHr5IQiYFdZEyy/a/Z3OpjCLle0rlmA1OUUEXS1et 2EGJFlHi24T/wiqgi7UIeqgskuo0ea8Fyld1WVMKc2cxSmIP+kMQzZ/PmsLX8iaOlASMGd TiI+TjgT+y1YyaVtUS0qXj2egUKkeVc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="IDkI/8Fc"; spf=pass (imf14.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.247 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692972369; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o5eD4gq5Ypmv7xNjaJcQB3ZOSw79lNA3YgufxQ7kbUU=; b=xNJecd7hd73J+WR3njCn2ICwRMwev9cl4txMjzxmr0Oui+R6KuT3pysitGIteV2Qk5LnGS wODv23AlwPlRBfpafeEZ15PjRDuhTWyFWZx+oAwKC1tFGCO19Rx01SI8bA6WVlU3bny+LI VlN/EwsNiobw447XzTI6X5ASZ+z/8vs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1692972368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o5eD4gq5Ypmv7xNjaJcQB3ZOSw79lNA3YgufxQ7kbUU=; b=IDkI/8FcKGXMrBLpAzKCujyKyUIvnRClPZG+PDDA+Kg6Ww/HgNrG0d8/UaYBPttRvdNV2G ImRsaH6EObyEWgQtf31bAS82oxf65cz7kpZXIj7D5nH1V4igKHLmt2T1OZkYhVy9UsI8OJ u9rq7LaZ7EE10dyazZwRdVBs5aqDaMI= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 28/29] xfs: support nowait semantics for xc_ctx_lock in xlog_cil_commit() Date: Fri, 25 Aug 2023 21:54:30 +0800 Message-Id: <20230825135431.1317785-29-hao.xu@linux.dev> In-Reply-To: <20230825135431.1317785-1-hao.xu@linux.dev> References: <20230825135431.1317785-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 96D83100034 X-Stat-Signature: az11nf8w4kaftoymjj1hptb7mjmwqfnf X-Rspam-User: X-HE-Tag: 1692972369-242929 X-HE-Meta: U2FsdGVkX1/RN6TVQqawaLgc2DijbnAnMyNPY2pmYmsa1Fd/e+kayIRDw8/AyIkR4uRFFdm4kzj0OwsSaVyYuq5+74ztDOu31UOa6NtlXSTz6ZhNR6AviWYfePPwNzPb+L2LkkyNvSPgBjDhartygsWeQ5nzt2PjYKzUXi69zDrfW6b8OIWZJ+s4Q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ity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Hao Xu Apply trylock logic for xc_ctx_lock in xlog_cil_commit() in nowait case and error out -EAGAIN for xlog_cil_commit(). Signed-off-by: Hao Xu --- fs/xfs/xfs_log_cil.c | 12 ++++++++++-- fs/xfs/xfs_log_priv.h | 2 +- fs/xfs/xfs_trans.c | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c index b31830ee36dd..6d054359bbb5 100644 --- a/fs/xfs/xfs_log_cil.c +++ b/fs/xfs/xfs_log_cil.c @@ -1613,7 +1613,7 @@ xlog_cil_process_intents( * background commit, returns without it held once background commits are * allowed again. */ -void +int xlog_cil_commit( struct xlog *log, struct xfs_trans *tp, @@ -1623,6 +1623,7 @@ xlog_cil_commit( struct xfs_cil *cil = log->l_cilp; struct xfs_log_item *lip, *next; uint32_t released_space = 0; + bool nowait = tp->t_flags & XFS_TRANS_NOWAIT; /* * Do all necessary memory allocation before we lock the CIL. @@ -1632,7 +1633,12 @@ xlog_cil_commit( xlog_cil_alloc_shadow_bufs(log, tp); /* lock out background commit */ - down_read(&cil->xc_ctx_lock); + if (nowait) { + if (!down_read_trylock(&cil->xc_ctx_lock)) + return -EAGAIN; + } else { + down_read(&cil->xc_ctx_lock); + } if (tp->t_flags & XFS_TRANS_HAS_INTENT_DONE) released_space = xlog_cil_process_intents(cil, tp); @@ -1668,6 +1674,8 @@ xlog_cil_commit( /* xlog_cil_push_background() releases cil->xc_ctx_lock */ xlog_cil_push_background(log); + + return 0; } /* diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index 41edaa0ae869..eb7a1241deab 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h @@ -580,7 +580,7 @@ int xlog_cil_init(struct xlog *log); void xlog_cil_init_post_recovery(struct xlog *log); void xlog_cil_destroy(struct xlog *log); bool xlog_cil_empty(struct xlog *log); -void xlog_cil_commit(struct xlog *log, struct xfs_trans *tp, +int xlog_cil_commit(struct xlog *log, struct xfs_trans *tp, xfs_csn_t *commit_seq, bool regrant); void xlog_cil_set_ctx_write_state(struct xfs_cil_ctx *ctx, struct xlog_in_core *iclog); diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index f1f84a3dd456..e5beda636a37 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -1037,7 +1037,9 @@ __xfs_trans_commit( xfs_trans_apply_sb_deltas(tp); xfs_trans_apply_dquot_deltas(tp); - xlog_cil_commit(log, tp, &commit_seq, regrant); + error = xlog_cil_commit(log, tp, &commit_seq, regrant); + if (error) + goto out_unreserve; xfs_trans_free(tp);