From patchwork Wed Nov 21 01:17:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10691511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93CE61923 for ; Wed, 21 Nov 2018 01:17:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A4B92AEC9 for ; Wed, 21 Nov 2018 01:17:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68C192B0A6; Wed, 21 Nov 2018 01:17:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 138402AEC9 for ; Wed, 21 Nov 2018 01:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726115AbeKULtP (ORCPT ); Wed, 21 Nov 2018 06:49:15 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:46344 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbeKULtP (ORCPT ); Wed, 21 Nov 2018 06:49:15 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAL1F0Q9056169; Wed, 21 Nov 2018 01:17:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=gFP1RFsSDptXJXWHJaW/hto/WsEBQjY4WZAepM5+J0U=; b=N92Ozy7bAnylkNgHj/G84axk4Y4x3VNXSJI7wrwY+x7vGMe18fuL1Q26jf44d77nXhoK rZMhYtTp/JTgMovoUNMrwOztouxsuTmv7I2RDtEEiAgaE9/eJ1PR/a9xuJMjwb3/VB5Y oR/sy51l7UyjVHJ00mSzCRsH6MuEmpzQTCxMsCwWQ3PIOfe1P0yRr1qVuyIOfbC33Kp8 a4MdJNX3/ONmNd5m3cHrLWtJHdDGH1eEnxgfixxcQ8ialFgLPtqmk43yXomM4pGIgpN7 oJ42UC0xnnIpAR2Dc3yRBVukPYIa7rw4wZOFzWLOoT85Ps1QgvXKZXmoSORU1oGH1QMq iw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2ntaxq6vq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Nov 2018 01:17:08 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAL1H7s7011163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Nov 2018 01:17:07 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wAL1H7N6018438; Wed, 21 Nov 2018 01:17:07 GMT Received: from localhost (/10.145.178.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Nov 2018 17:17:06 -0800 Date: Tue, 20 Nov 2018 17:17:06 -0800 From: "Darrick J. Wong" To: Dave Chinner Cc: xfs Subject: [PATCH] xfs: reflink should flush after an unaligned directio cow write Message-ID: <20181121011706.GO6792@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9083 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811210009 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 From: Darrick J. Wong If userspace hands us a not-block-aligned directio write, we'll fall back to a buffered write for the read-modify-write operation. Unfortunately, we don't flush the page cache after a successful fallback CoW, which means we break userspace's expectation that the data has been sent to the drive. Fix that by upgrading the iocb to DSYNC so that the buffered CoW is synchronous. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index e47425071e65..675da7e9c001 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -692,6 +692,8 @@ xfs_file_write_iter( struct xfs_inode *ip = XFS_I(inode); ssize_t ret; size_t ocount = iov_iter_count(from); + bool was_dsync = iocb->ki_flags & IOCB_DSYNC; + int error; XFS_STATS_INC(ip->i_mount, xs_write_calls); @@ -714,9 +716,13 @@ xfs_file_write_iter( ret = xfs_file_dio_aio_write(iocb, from); if (ret != -EREMCHG) return ret; + iocb->ki_flags |= IOCB_DSYNC; } - return xfs_file_buffered_aio_write(iocb, from); + error = xfs_file_buffered_aio_write(iocb, from); + if (!was_dsync) + iocb->ki_flags &= ~IOCB_DSYNC; + return error; } static void