From patchwork Thu Aug 31 13:47:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9932217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 35EFF602F0 for ; Thu, 31 Aug 2017 13:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26A2228944 for ; Thu, 31 Aug 2017 13:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B3DE28978; Thu, 31 Aug 2017 13:47:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F040728944 for ; Thu, 31 Aug 2017 13:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbdHaNrY (ORCPT ); Thu, 31 Aug 2017 09:47:24 -0400 Received: from verein.lst.de ([213.95.11.211]:55546 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751034AbdHaNrY (ORCPT ); Thu, 31 Aug 2017 09:47:24 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 670979EF3C; Thu, 31 Aug 2017 15:47:22 +0200 (CEST) Date: Thu, 31 Aug 2017 15:47:22 +0200 From: Christoph Hellwig To: Amir Goldstein Cc: "Darrick J . Wong" , Christoph Hellwig , Dave Chinner , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Josef Bacik , stable@vger.kernel.org Subject: Re: [PATCH] xfs: fix incorrect log_flushed on fsync Message-ID: <20170831134722.GA6912@lst.de> References: <1504100302-3297-1-git-send-email-amir73il@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1504100302-3297-1-git-send-email-amir73il@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I think something like the following patch (totally untested, just an idea) should fix the issue, right? --- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index c4893e226fd8..555fcae9a18f 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -135,7 +135,7 @@ xfs_file_fsync( struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; int error = 0; - int log_flushed = 0; + unsigned int flushseq; xfs_lsn_t lsn = 0; trace_xfs_file_fsync(ip); @@ -143,6 +143,7 @@ xfs_file_fsync( error = file_write_and_wait_range(file, start, end); if (error) return error; + flushseq = READ_ONCE(mp->m_flushseq); if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; @@ -181,7 +182,7 @@ xfs_file_fsync( } if (lsn) { - error = _xfs_log_force_lsn(mp, lsn, XFS_LOG_SYNC, &log_flushed); + error = _xfs_log_force_lsn(mp, lsn, XFS_LOG_SYNC, NULL); ip->i_itemp->ili_fsync_fields = 0; } xfs_iunlock(ip, XFS_ILOCK_SHARED); @@ -193,8 +194,9 @@ xfs_file_fsync( * an already allocated file and thus do not have any metadata to * commit. */ - if (!log_flushed && !XFS_IS_REALTIME_INODE(ip) && - mp->m_logdev_targp == mp->m_ddev_targp) + if (!XFS_IS_REALTIME_INODE(ip) && + mp->m_logdev_targp == mp->m_ddev_targp && + flushseq == READ_ONCE(mp->m_flushseq)) xfs_blkdev_issue_flush(mp->m_ddev_targp); return error; diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index bcb2f860e508..3c0cbb98581e 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -2922,6 +2922,8 @@ xlog_state_done_syncing( iclog->ic_state = XLOG_STATE_DONE_SYNC; } + log->l_mp->m_flushseq++; + /* * Someone could be sleeping prior to writing out the next * iclog buffer, we wake them all, one will get to do the diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index e0792d036be2..556e01a0175e 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -79,6 +79,7 @@ typedef struct xfs_mount { struct percpu_counter m_icount; /* allocated inodes counter */ struct percpu_counter m_ifree; /* free inodes counter */ struct percpu_counter m_fdblocks; /* free block counter */ + unsigned int m_flushseq; struct xfs_buf *m_sb_bp; /* buffer for superblock */ char *m_fsname; /* filesystem name */