From patchwork Thu Nov 24 10:55:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9445177 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 D2AD46075F for ; Thu, 24 Nov 2016 10:56:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC7D4269A3 for ; Thu, 24 Nov 2016 10:56:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFEEB27C14; Thu, 24 Nov 2016 10:56:23 +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 6AF18269A3 for ; Thu, 24 Nov 2016 10:56:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938700AbcKXK4T (ORCPT ); Thu, 24 Nov 2016 05:56:19 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:38175 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964986AbcKXK4A (ORCPT ); Thu, 24 Nov 2016 05:56:00 -0500 Received: by mail-wm0-f54.google.com with SMTP id f82so56384442wmf.1 for ; Thu, 24 Nov 2016 02:56:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WZIOVvIn4s7iOXH6YuM4CMy++Nmoglz8wCoQUerVztI=; b=RrqxKRvH+y2tb+RN/zGeY3up3ElS1YaWQKKfL1ulrC8BF5FQx+75y3WgJYT9Q/7qcY e3/a4TBo4eNDK8+mbnDePDprKlGtLwT7xToWLXCii/fHGHOlgXwtGEtNHJb/8YmzmcpB vCcfnBaKK5XT8jwmUErKUUh2LyGTevPXDxThqPyLR/5O5E6OSefY8IAD/Uic/KSPZU4U x2AS61fQae6T/+Su+PPqTt3LYhyXwAl7t5sQp/RMDGLfJgBGHv+CI/MHBYGQcYNNE8in N5cZa1dxDsazu2MslQlKykVieDW1TgReMBEu8eWEhiZLbVpkonrAzzeGs2me7PfeILjO MU2Q== X-Gm-Message-State: AKaTC02vCqEYXCF4Ad+dRyZhud0Pk4PlOyILCoC8LZuITWJ0ghwkPFCy1QPRvIu47d5ZRTTw X-Received: by 10.194.112.196 with SMTP id is4mr1903884wjb.92.1479984959222; Thu, 24 Nov 2016 02:55:59 -0800 (PST) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id g73sm7587416wme.16.2016.11.24.02.55.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2016 02:55:58 -0800 (PST) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] ovl: intercept fsync Date: Thu, 24 Nov 2016 11:55:44 +0100 Message-Id: <1479984944-1017-9-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1479984944-1017-1-git-send-email-mszeredi@redhat.com> References: <1479984944-1017-1-git-send-email-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fsync is really an inode operation (AFAICS) so a doing it on a O_RDONLY file descriptor should flush any data written through an O_WRONLY file descriptor for example. To make this work correctly in case the file is copied up after being opened for read intercept the fsync fop, similarly to read_iter and mmap. Signed-off-by: Miklos Szeredi --- fs/overlayfs/inode.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 25b31c6ebe9e..f522cb350f3c 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -412,6 +412,24 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma) return file->f_op->mmap(file, vma); } +static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) +{ + int ret; + + if (likely(ovl_file_is_lower(file))) { + return OVL_CALL_REAL_FOP(file, + fsync(file, start, end, datasync)); + } + file = filp_clone_open(file); + if (IS_ERR(file)) + return PTR_ERR(file); + + ret = vfs_fsync_range(file, start, end, datasync); + fput(file); + + return ret; +} + static struct ovl_fops *ovl_fops_find(const struct file_operations *orig) { struct ovl_fops *ofop; @@ -453,9 +471,8 @@ static struct ovl_fops *ovl_fops_get(struct file *file) ofop->fops.read_iter = ovl_read_iter; if (orig->mmap) ofop->fops.mmap = ovl_mmap; - - /* These will need to be intercepted: */ - ofop->fops.fsync = orig->fsync; + if (orig->fsync) + ofop->fops.fsync = ovl_fsync; /* * These should be intercepted, but they are very unlikely to be