From patchwork Mon Oct 10 19:13:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9369873 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 8337C60487 for ; Mon, 10 Oct 2016 19:26:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D47929A10 for ; Mon, 10 Oct 2016 19:26:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 619C729A15; Mon, 10 Oct 2016 19:26:53 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 DA4C329A10 for ; Mon, 10 Oct 2016 19:26:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751488AbcJJT0v (ORCPT ); Mon, 10 Oct 2016 15:26:51 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:34534 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751423AbcJJT0v (ORCPT ); Mon, 10 Oct 2016 15:26:51 -0400 Received: by mail-qk0-f195.google.com with SMTP id n189so7616936qke.1 for ; Mon, 10 Oct 2016 12:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=53mXV1Y8Z0AEVrypRXS05bS7BN+9GXXQfSYSudyO8A8=; b=LsAP4Qpu8CjZQkDRb0kK5ViV1YUhvNd0dXDUpN0pmjsMyWtM5RNJbreDU7eH5a8Jgo z2KKpmBXPBrLI8HenfgQEV7zp1lrqM5ipClFYyxT6PP7TrCN49Dy/VE6RBk1FXNFBSHZ +cM88exuyxbp72zGdAJe54z6rCnHBnyAbfGRtvqrLZF7gIbJxk/T+yWvlU0DSnzvMVZD 6Lpo5Rey+oWGpwjQfr6GLqrxKiXhKKszDM2XBtJnTZT+USR78m049hFZE+8GdP2lUIgM 37+8wEtHtbFcKYbjaQ9V16U5HKfu9/6sRy+WQxL0xF/RwgE90ECmbNQ0gGZoK/Dkg8E4 lFuQ== 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=53mXV1Y8Z0AEVrypRXS05bS7BN+9GXXQfSYSudyO8A8=; b=I7cw7+qlEFC8BQrX36z25KmoJJwCLTIosFjFHviY49RKEvDt8d7iIVkI2v/wqCKe/Q RYZg09sxZeHChJWY6uk/1ssykipE83EP8qtNVw6plNdEsZ9tnfLIUlBoA4VUpjwQNEjU 0SmPXuBHDwDi5I9gMiyP1oyxHhKs2TCfdPYSo6zaQ7iQSqThw5Ue9d2DL5FNMpG2+922 s68EjYRkAxxTCEH5fPGfekGkbnCR5H0ER0915EauwjlnZMWih+sWpGRK/mB983dhWyNS IVrXeabu1Mn5fkfS/HMKbkDyPDHdKZwsnUMt+LAvSfjaeMx9Ar6htA7mjJ6R3Z4IG4ay PxzA== X-Gm-Message-State: AA6/9RmEl7DqwHSRBzENycf1JeTnilgHabOtEu0tzNT4aWQ8YpjdAMX3vYxQ54KdoSha4w== X-Received: by 10.194.118.131 with SMTP id km3mr31608892wjb.173.1476126829386; Mon, 10 Oct 2016 12:13:49 -0700 (PDT) Received: from amir-VirtualBox.Home (bzq-79-180-3-185.red.bezeqint.net. [79.180.3.185]) by smtp.gmail.com with ESMTPSA id hb5sm83688wjc.5.2016.10.10.12.13.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Oct 2016 12:13:48 -0700 (PDT) From: Amir Goldstein To: linux-fsdevel@vger.kernel.org Cc: Jan Kara , Lino Sanfilippo , Eric Paris , Al Viro Subject: [RFC][PATCH 6/7] fanotify: add support for create/attrib/rename/delete events Date: Mon, 10 Oct 2016 22:13:03 +0300 Message-Id: <1476126784-12520-7-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476126784-12520-1-git-send-email-amir73il@gmail.com> References: <1476126784-12520-1-git-send-email-amir73il@gmail.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 Add support for create/attrib/rename/delete events with data type FSNOTIFY_EVENT_DENTRY, which can be reported on a watched directory inode. New dentry events may pass parent directory's path on event fd, which may break old programs that request FAN_ALL_EVENTS. Ignore dentry events unless user explicitly set the new FAN_EVENT_INFO_PARENT flag to fanotify_init(). A mount watch cannot get dentry events, because the mount point from which those events were created is unavailable inforamtion. Legacy inotify events that are still not supported are DELETE_SELF and MOVE_FROM, whose event data type is still FSNOTIFY_EVENT_INODE. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 7 +++++++ fs/notify/fanotify/fanotify_user.c | 12 ++++++++++++ include/uapi/linux/fanotify.h | 26 ++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index fb2b852..378101c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -212,9 +212,16 @@ static int fanotify_handle_event(struct fsnotify_group *group, BUILD_BUG_ON(FAN_ACCESS != FS_ACCESS); BUILD_BUG_ON(FAN_MODIFY != FS_MODIFY); + BUILD_BUG_ON(FAN_ATTRIB != FS_ATTRIB); BUILD_BUG_ON(FAN_CLOSE_NOWRITE != FS_CLOSE_NOWRITE); BUILD_BUG_ON(FAN_CLOSE_WRITE != FS_CLOSE_WRITE); BUILD_BUG_ON(FAN_OPEN != FS_OPEN); + BUILD_BUG_ON(FAN_MOVED_TO != FS_MOVED_TO); + BUILD_BUG_ON(FAN_MOVED_FROM != FS_MOVED_FROM); + BUILD_BUG_ON(FAN_CREATE != FS_CREATE); + BUILD_BUG_ON(FAN_DELETE != FS_DELETE); + BUILD_BUG_ON(FAN_DELETE_SELF != FS_DELETE_SELF); + BUILD_BUG_ON(FAN_MOVE_SELF != FS_MOVE_SELF); BUILD_BUG_ON(FAN_EVENT_ON_CHILD != FS_EVENT_ON_CHILD); BUILD_BUG_ON(FAN_Q_OVERFLOW != FS_Q_OVERFLOW); BUILD_BUG_ON(FAN_OPEN_PERM != FS_OPEN_PERM); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 789962c..616769a 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -907,6 +907,18 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, group->fanotify_data.flags & FAN_EVENT_INFO_PARENT) mnt = path.mnt; + /* + * New dentry events may pass parent directory's path on event fd, + * which may break old programs that request FAN_ALL_EVENTS. + * Ignore dentry events unless user explicitly set the new + * FAN_EVENT_INFO_PARENT flag to fanotify_init(). + * Mount watch cannot get dentry events, because the mount point + * from which those events were created is unavailable inforamtion. + */ + if ((flags & FAN_MARK_MOUNT) || + !(group->fanotify_data.flags & FAN_EVENT_INFO_PARENT)) + mask &= ~FAN_DENTRY_EVENTS; + /* create/update an inode mark */ switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) { case FAN_MARK_ADD: diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 8e58765..3389da0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -6,9 +6,17 @@ /* the following events that user-space can register for */ #define FAN_ACCESS 0x00000001 /* File was accessed */ #define FAN_MODIFY 0x00000002 /* File was modified */ +#define FAN_ATTRIB 0x00000004 /* Metadata changed */ #define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ #define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ #define FAN_OPEN 0x00000020 /* File was opened */ +#define FAN_MOVED_FROM 0x00000040 /* File was moved from X */ +#define FAN_MOVED_TO 0x00000080 /* File was moved to Y */ +#define FAN_CREATE 0x00000100 /* Subfile was created */ +#define FAN_DELETE 0x00000200 /* Subfile was deleted */ +#define FAN_DELETE_SELF 0x00000400 /* Self was deleted */ +#define FAN_MOVE_SELF 0x00000800 /* Self was moved */ + #define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ @@ -21,6 +29,7 @@ /* helper events */ #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ +#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) /* moves */ /* flags used for fanotify_init() */ #define FAN_CLOEXEC 0x00000001 @@ -69,10 +78,19 @@ * the future and not break backward compatibility. Apps will get only the * events that they originally wanted. Be sure to add new events here! */ -#define FAN_ALL_EVENTS (FAN_ACCESS |\ - FAN_MODIFY |\ - FAN_CLOSE |\ - FAN_OPEN) + +/* Events reported with data type FSNOTIFY_EVENT_PATH */ +#define FAN_PATH_EVENTS (FAN_ACCESS |\ + FAN_MODIFY |\ + FAN_CLOSE |\ + FAN_OPEN) + +/* Events reported with data type FSNOTIFY_EVENT_DENTRY */ +#define FAN_DENTRY_EVENTS (FAN_ATTRIB |\ + FAN_MOVED_TO | FAN_MOVE_SELF |\ + FAN_CREATE | FAN_DELETE) + +#define FAN_ALL_EVENTS (FAN_PATH_EVENTS | FAN_DENTRY_EVENTS) /* * All events which require a permission response from userspace