Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4750677pxj; Tue, 25 May 2021 15:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLAweg90x5hgjSoGMRaZ9zKlUMXLAgeRo3o9nGckv+KTa2S7L9SAqK3NuF11kxbbmnbDP0 X-Received: by 2002:a02:5b0a:: with SMTP id g10mr28637015jab.2.1621982930663; Tue, 25 May 2021 15:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621982930; cv=none; d=google.com; s=arc-20160816; b=H8+mEPWdRr/TIPLjUM1DhbVzbglVg8gy2Q2xT2coEsUDk74dkc0O/FKSFLTv9gxcZv 9GULKyftUexPxgMIWIyWJ2pjd84DDg87ELTzXxlPpz1JykRVcFzSnpiNmZQAQfGWQdGc 28Rie9XFFI2czWJioRPXrtnlmYrz0Omon33jz5SE2ftsccx23h1zEoPDLfKsQkeU8aDE k44gdcgQhgY8J2u4QqUE+Ek0iXQuN94fCcGC7fci3k685dGixKTLxWIJMcIwevaoPkIs OGyykEWGJHrk46njhtQeFZrRPOuSbKJZ9CGBWCrlba4HifX5VrNIdE5onuImF+mOAyEf uI1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=n8mmJErlK1/R0AjpnjEWfYoV3Zlq3ariIqAZo6Hblb4=; b=Xcr7xmKQ+Q8vdICc8Ux08hGh4Vi9OcV1EPyAQiFy0xrqT17txqQIo/mnHrqmwqYo+Q mhPeeo9CQi30U8+qm7d6XL7IEETf+hvre64axN1v5jpudlc3vQ6SMNxvINtnH50Ek7uo Y7jHMLEVjRuc6C2cp/km4rg7qUv/b6LFWZ0iOGT/6ka3QyFuJapfcx6vMRSBVZl1ppXO ZkiFpYY54tk6orvWhggoFfCTM8KEzJ1i0cwFEtWngRnuQlwaU5BNcShbHVUsND7hnmuF lXZavhUxCPAvtHlS5N/pZWJgfYiX7I0Rs5uLhtkltDrGaw5p1NLcjDLbV+aoVkY5qLdP Jwuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S7WwcUxQ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si20068554jap.36.2021.05.25.15.48.38; Tue, 25 May 2021 15:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S7WwcUxQ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233479AbhEYVnD (ORCPT + 99 others); Tue, 25 May 2021 17:43:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:49442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233467AbhEYVnB (ORCPT ); Tue, 25 May 2021 17:43:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E649613D5; Tue, 25 May 2021 21:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621978891; bh=Ff90q5Kz0o+BMBRcQ7Rxn+PAVevoQMBbngm/RLK1s+8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S7WwcUxQKZjNrqh4HMAxGnxr7VCwquen6SJALt7e7iV5i4bX++9K8LxIOp1kIRs5O 9fLtSBpQdakVBftuhgpL4oFWpbo2sKjHVDMeZOcc+U/LPb3YEm1cZdPkvOb0fKwTph M7CkrFhzVExeTD7ns32hjrV6zpJlDrxFTt9gbb60Izc+41it5zfmeLQz6mn6Gmtyky Z7dqmDRkehTVa27itdEh+TeMb8S9UMmgOs0+FuntutheBG+gJkAyxxmHiwhTkWY0Cc EBpA5J63DL/mPwj7geODr3bz9PnyoVwd/6rImPFri9U0i1awZLAnS97c2mKicyRopd oJevdxgpT8cog== Date: Tue, 25 May 2021 14:41:30 -0700 From: "Darrick J. Wong" To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, Christoph Hellwig , Dave Chinner , ceph-devel@vger.kernel.org, Chao Yu , Damien Le Moal , "Darrick J. Wong" , Jaegeuk Kim , Jeff Layton , Johannes Thumshirn , linux-cifs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mm@kvack.org, linux-xfs@vger.kernel.org, Miklos Szeredi , Steve French , Ted Tso , Matthew Wilcox Subject: Re: [PATCH 08/13] xfs: Convert double locking of MMAPLOCK to use VFS helpers Message-ID: <20210525214130.GP202121@locust> References: <20210525125652.20457-1-jack@suse.cz> <20210525135100.11221-8-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210525135100.11221-8-jack@suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, May 25, 2021 at 03:50:45PM +0200, Jan Kara wrote: > Convert places in XFS that take MMAPLOCK for two inodes to use helper > VFS provides for it (filemap_invalidate_down_write_two()). Note that > this changes lock ordering for MMAPLOCK from inode number based ordering > to pointer based ordering VFS generally uses. > > Signed-off-by: Jan Kara Reviewed-by: Darrick J. Wong --D > --- > fs/xfs/xfs_bmap_util.c | 15 ++++++++------- > fs/xfs/xfs_inode.c | 37 +++++++++++-------------------------- > 2 files changed, 19 insertions(+), 33 deletions(-) > > diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c > index a5e9d7d34023..8a5cede59f3f 100644 > --- a/fs/xfs/xfs_bmap_util.c > +++ b/fs/xfs/xfs_bmap_util.c > @@ -1582,7 +1582,6 @@ xfs_swap_extents( > struct xfs_bstat *sbp = &sxp->sx_stat; > int src_log_flags, target_log_flags; > int error = 0; > - int lock_flags; > uint64_t f; > int resblks = 0; > unsigned int flags = 0; > @@ -1594,8 +1593,8 @@ xfs_swap_extents( > * do the rest of the checks. > */ > lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); > - lock_flags = XFS_MMAPLOCK_EXCL; > - xfs_lock_two_inodes(ip, XFS_MMAPLOCK_EXCL, tip, XFS_MMAPLOCK_EXCL); > + filemap_invalidate_down_write_two(VFS_I(ip)->i_mapping, > + VFS_I(tip)->i_mapping); > > /* Verify that both files have the same format */ > if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { > @@ -1667,7 +1666,6 @@ xfs_swap_extents( > * or cancel will unlock the inodes from this point onwards. > */ > xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); > - lock_flags |= XFS_ILOCK_EXCL; > xfs_trans_ijoin(tp, ip, 0); > xfs_trans_ijoin(tp, tip, 0); > > @@ -1786,13 +1784,16 @@ xfs_swap_extents( > trace_xfs_swap_extent_after(ip, 0); > trace_xfs_swap_extent_after(tip, 1); > > +out_unlock_ilock: > + xfs_iunlock(ip, XFS_ILOCK_EXCL); > + xfs_iunlock(tip, XFS_ILOCK_EXCL); > out_unlock: > - xfs_iunlock(ip, lock_flags); > - xfs_iunlock(tip, lock_flags); > + filemap_invalidate_up_write_two(VFS_I(ip)->i_mapping, > + VFS_I(tip)->i_mapping); > unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); > return error; > > out_trans_cancel: > xfs_trans_cancel(tp); > - goto out_unlock; > + goto out_unlock_ilock; > } > diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c > index 53bb5fc33621..11616c9b37f8 100644 > --- a/fs/xfs/xfs_inode.c > +++ b/fs/xfs/xfs_inode.c > @@ -537,12 +537,10 @@ xfs_lock_inodes( > } > > /* > - * xfs_lock_two_inodes() can only be used to lock one type of lock at a time - > - * the mmaplock or the ilock, but not more than one type at a time. If we lock > - * more than one at a time, lockdep will report false positives saying we have > - * violated locking orders. The iolock must be double-locked separately since > - * we use i_rwsem for that. We now support taking one lock EXCL and the other > - * SHARED. > + * xfs_lock_two_inodes() can only be used to lock ilock. The iolock and > + * mmaplock must be double-locked separately since we use i_rwsem and > + * invalidate_lock for that. We now support taking one lock EXCL and the > + * other SHARED. > */ > void > xfs_lock_two_inodes( > @@ -560,15 +558,8 @@ xfs_lock_two_inodes( > ASSERT(hweight32(ip1_mode) == 1); > ASSERT(!(ip0_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL))); > ASSERT(!(ip1_mode & (XFS_IOLOCK_SHARED|XFS_IOLOCK_EXCL))); > - ASSERT(!(ip0_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) || > - !(ip0_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))); > - ASSERT(!(ip1_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) || > - !(ip1_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))); > - ASSERT(!(ip1_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) || > - !(ip0_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))); > - ASSERT(!(ip0_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL)) || > - !(ip1_mode & (XFS_ILOCK_SHARED|XFS_ILOCK_EXCL))); > - > + ASSERT(!(ip0_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL))); > + ASSERT(!(ip1_mode & (XFS_MMAPLOCK_SHARED|XFS_MMAPLOCK_EXCL))); > ASSERT(ip0->i_ino != ip1->i_ino); > > if (ip0->i_ino > ip1->i_ino) { > @@ -3731,11 +3722,8 @@ xfs_ilock2_io_mmap( > ret = xfs_iolock_two_inodes_and_break_layout(VFS_I(ip1), VFS_I(ip2)); > if (ret) > return ret; > - if (ip1 == ip2) > - xfs_ilock(ip1, XFS_MMAPLOCK_EXCL); > - else > - xfs_lock_two_inodes(ip1, XFS_MMAPLOCK_EXCL, > - ip2, XFS_MMAPLOCK_EXCL); > + filemap_invalidate_down_write_two(VFS_I(ip1)->i_mapping, > + VFS_I(ip2)->i_mapping); > return 0; > } > > @@ -3745,12 +3733,9 @@ xfs_iunlock2_io_mmap( > struct xfs_inode *ip1, > struct xfs_inode *ip2) > { > - bool same_inode = (ip1 == ip2); > - > - xfs_iunlock(ip2, XFS_MMAPLOCK_EXCL); > - if (!same_inode) > - xfs_iunlock(ip1, XFS_MMAPLOCK_EXCL); > + filemap_invalidate_up_write_two(VFS_I(ip1)->i_mapping, > + VFS_I(ip2)->i_mapping); > inode_unlock(VFS_I(ip2)); > - if (!same_inode) > + if (ip1 != ip2) > inode_unlock(VFS_I(ip1)); > } > -- > 2.26.2 >