From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78639C10F14 for ; Tue, 23 Apr 2019 06:51:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4ABD120643 for ; Tue, 23 Apr 2019 06:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726213AbfDWGvY (ORCPT ); Tue, 23 Apr 2019 02:51:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfDWGvY (ORCPT ); Tue, 23 Apr 2019 02:51:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9A2B3082263; Tue, 23 Apr 2019 06:51:23 +0000 (UTC) Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F9D85D71E; Tue, 23 Apr 2019 06:51:22 +0000 (UTC) From: Murphy Zhou To: miklos@szeredi.hu, linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: amir73il@gmail.com, Murphy Zhou Subject: [PATCH] ovl: add RWF_NONITIFY flag to skip wrong duplicate fanotify event Date: Tue, 23 Apr 2019 14:50:24 +0800 Message-Id: <20190423065024.12695-1-jencce.kernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 23 Apr 2019 06:51:24 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Overlays ovl_iter_write calls vfs_iter_write to write on real file, in which calls fsnotify_modify on this change, however vfs_write also calls fsnotify_modify after ovl_iter_write. The first notification sent by vfs_iter_write grabs marks from upper inode and overlay mnt, because of its fake path. The second one sent by vfs_write grabs marks from ovl inode and ovl mnt. LTP fanotify06 add modify mark for mnt point, then add ignore modify mask on testfile, then truncate and write the file. Because the ignore mask is marked on ovl inode, not the upper inode, the first event is not masked like the second one. So we get a modification event even with a mask on the file. Proposing fixing this by add a new RWF flag to skip fsnotify on this IO. vfs_iter_write used by ovl can use this flag to skip one duplicate event. Signed-off-by: Murphy Zhou --- fs/overlayfs/file.c | 2 +- fs/read_write.c | 2 +- include/uapi/linux/fs.h | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 84dd957efa24..0827199a5311 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -242,7 +242,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter) old_cred = ovl_override_creds(file_inode(file)->i_sb); file_start_write(real.file); ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, - ovl_iocb_to_rwf(iocb)); + ovl_iocb_to_rwf(iocb)|RWF_NONOTIFY); file_end_write(real.file); revert_creds(old_cred); diff --git a/fs/read_write.c b/fs/read_write.c index 61b43ad7608e..aec751cacedf 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -957,7 +957,7 @@ static ssize_t do_iter_write(struct file *file, struct iov_iter *iter, ret = do_iter_readv_writev(file, iter, pos, WRITE, flags); else ret = do_loop_readv_writev(file, iter, pos, WRITE, flags); - if (ret > 0) + if (ret > 0 && !(flags & RWF_NONOTIFY)) fsnotify_modify(file); return ret; } diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 121e82ce296b..103f1a9375f2 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -342,8 +342,11 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* do not notify this IO */ +#define RWF_NONOTIFY ((__force __kernel_rwf_t)0x00000020) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_NONOTIFY) #endif /* _UAPI_LINUX_FS_H */ -- 2.21.0