From patchwork Thu May 20 12:25:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 12270099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F0F6C43460 for ; Thu, 20 May 2021 12:25:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0959C611ED for ; Thu, 20 May 2021 12:25:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0959C611ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9B6E56B00CD; Thu, 20 May 2021 08:25:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9682C6B00CE; Thu, 20 May 2021 08:25:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 856496B00CF; Thu, 20 May 2021 08:25:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 5494B6B00CD for ; Thu, 20 May 2021 08:25:55 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E05B2803148B for ; Thu, 20 May 2021 12:25:54 +0000 (UTC) X-FDA: 78161531028.24.01D3BA5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 739ABE0007C4 for ; Thu, 20 May 2021 12:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621513554; 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=GyKgynniRDUoKP5K5rhBmL1x4hLij6EvDAklIQldN/k=; b=J+uzWEnqwUsRbCfCfAve+LS6xvfsL78iNPpRcRN0jncSuAu3x3rH/mgEQRMyu2se7Z8T6i YG5W0py76X+hfYKowWr+lNAeJpUEYODc+mvbJ0rmEermCi4vNGA0aixhUdwedgIHlNzfJh zyRJU8t/orNi3IwGBBEjrDeevMH1TDs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-499-iGAexnAZPtOlhpFAS6pTVA-1; Thu, 20 May 2021 08:25:52 -0400 X-MC-Unique: iGAexnAZPtOlhpFAS6pTVA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BBE0180FD61; Thu, 20 May 2021 12:25:51 +0000 (UTC) Received: from max.com (unknown [10.40.195.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC70760C04; Thu, 20 May 2021 12:25:49 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , cluster-devel@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Jan Kara , Andreas Gruenbacher Subject: [PATCH 4/6] gfs2: Encode glock holding and retry flags in journal_info Date: Thu, 20 May 2021 14:25:34 +0200 Message-Id: <20210520122536.1596602-5-agruenba@redhat.com> In-Reply-To: <20210520122536.1596602-1-agruenba@redhat.com> References: <20210520122536.1596602-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J+uzWEnq; spf=none (imf05.hostedemail.com: domain of agruenba@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=agruenba@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 739ABE0007C4 X-Stat-Signature: u6khrqrebqu5saz5gg8a73c9tj9buujr X-HE-Tag: 1621513552-853392 X-Bogosity: 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: Use the lowest two bits in current->journal_info to encode when we're holding a glock and when an operation holding a glock needs to be retried. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/incore.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index aa8d1a23132d..e32433df119c 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h @@ -871,14 +871,45 @@ static inline unsigned gfs2_max_stuffed_size(const struct gfs2_inode *ip) return GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); } +/* + * Transactions are always memory aligned, so we use bit 0 of + * current->journal_info to indicate when we're holding a glock and so taking + * random additional glocks might deadlock, and bit 1 to indicate when such an + * operation needs to be retried after dropping and re-acquiring that "outer" + * glock. + */ + static inline struct gfs2_trans *current_trans(void) { - return current->journal_info; + return (void *)((long)current->journal_info & ~3); } static inline void set_current_trans(struct gfs2_trans *tr) { - current->journal_info = tr; + long flags = (long)current->journal_info & 3; + current->journal_info = (void *)((long)tr | flags); +} + +static inline bool current_holds_glock(void) +{ + return (long)current->journal_info & 1; +} + +static inline bool current_needs_retry(void) +{ + return (long)current->journal_info & 2; +} + +static inline void set_current_holds_glock(bool b) +{ + current->journal_info = + (void *)(((long)current->journal_info & ~1) | b); +} + +static inline void set_current_needs_retry(bool b) +{ + current->journal_info = + (void *)(((long)current->journal_info & ~2) | (b << 1)); } #endif /* __INCORE_DOT_H__ */