From patchwork Fri Feb 17 16:09:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9580327 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 AE0F0600F6 for ; Fri, 17 Feb 2017 16:10:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A064E28701 for ; Fri, 17 Feb 2017 16:10:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 950B728730; Fri, 17 Feb 2017 16:10:29 +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 47B4328701 for ; Fri, 17 Feb 2017 16:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934804AbdBQQKN (ORCPT ); Fri, 17 Feb 2017 11:10:13 -0500 Received: from mail-wr0-f171.google.com ([209.85.128.171]:34175 "EHLO mail-wr0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934802AbdBQQKM (ORCPT ); Fri, 17 Feb 2017 11:10:12 -0500 Received: by mail-wr0-f171.google.com with SMTP id z61so32492064wrc.1 for ; Fri, 17 Feb 2017 08:10:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G3m9TpAq/2FAldjwvq9RDrBQE+deSJO46EKoziX3f3M=; b=PAzYvhn6FP+txlwriSN5PUHF7nuFVKoKpgIRszbssUK+MeHsZ3/jeP9Lux0jra5vWG xZmuhqbODVDAICmhEpKTXWMT2RYOzaOndKq3rXTSYgAG/R3qSyJCH2GwLeR1sH7lHTaC DKF0WRykCBmtiDdzFxUJytYdOvzr2SXeqnYLXSvMBjmunw3KZSZ8U/dzrzXhSZpXTA/S XrkV0WUBJPOikpsL7Iutvk4JKdPz1gMbgmei2h/JBUkCO+pZzfU9QMrXsu8bdkVcCDjE GkoE/r0fd90uQt5JLErSqy57YN22C3Y1g12cyN2f15yYBtd+BqCCcp253CrNfonurXZD RZDA== X-Gm-Message-State: AMke39kXtdQMJXG0t8ClGOdZOUZuNcZ77byzWqLhm/BbeyVYr9VghrILh/wNi39CdUD5LWXX X-Received: by 10.223.136.50 with SMTP id d47mr8127513wrd.167.1487347795611; Fri, 17 Feb 2017 08:09:55 -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 h23sm4538793wrc.48.2017.02.17.08.09.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 08:09:54 -0800 (PST) From: Miklos Szeredi To: Al Viro Cc: linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 9/9] vfs: intercept fsync on overlay files Date: Fri, 17 Feb 2017 17:09:38 +0100 Message-Id: <1487347778-18596-10-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1487347778-18596-1-git-send-email-mszeredi@redhat.com> References: <1487347778-18596-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 operation, similarly to read_iter and mmap. Signed-off-by: Miklos Szeredi --- fs/overlay_util.c | 19 +++++++++++++++++++ include/linux/fs.h | 3 +++ include/linux/overlay_util.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/fs/overlay_util.c b/fs/overlay_util.c index 063f8c5719d1..dae9d23b1519 100644 --- a/fs/overlay_util.c +++ b/fs/overlay_util.c @@ -37,6 +37,25 @@ ssize_t overlay_read_iter(struct file *file, struct kiocb *kio, } EXPORT_SYMBOL(overlay_read_iter); +int overlay_fsync(struct file *file, loff_t start, loff_t end, + int datasync) +{ + int ret; + + if (likely(overlay_file_consistent(file))) + return file->f_op->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; +} +EXPORT_SYMBOL(overlay_fsync); + int overlay_mmap(struct file *file, struct vm_area_struct *vma) { if (unlikely(!overlay_file_consistent(file))) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 1293005de2e3..1cfa3b33659c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1748,6 +1748,9 @@ static inline int call_mmap(struct file *file, struct vm_area_struct *vma) static inline int call_fsync(struct file *file, loff_t start, loff_t end, int datasync) { + if (unlikely(is_overlay_file(file))) + return overlay_fsync(file, start, end, datasync); + return file->f_op->fsync(file, start, end, datasync); } diff --git a/include/linux/overlay_util.h b/include/linux/overlay_util.h index 2cd66bc316cc..06a0dd923404 100644 --- a/include/linux/overlay_util.h +++ b/include/linux/overlay_util.h @@ -11,5 +11,7 @@ struct vm_area_struct; extern ssize_t overlay_read_iter(struct file *file, struct kiocb *kio, struct iov_iter *iter); extern int overlay_mmap(struct file *file, struct vm_area_struct *vma); +extern int overlay_fsync(struct file *file, loff_t start, loff_t end, + int datasync); #endif /* _LINUX_OVERLAY_FS_H */