From patchwork Sat Sep 1 07:41:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10584635 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 E885316B1 for ; Sat, 1 Sep 2018 07:41:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6D532AE54 for ; Sat, 1 Sep 2018 07:41:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAA322AE77; Sat, 1 Sep 2018 07:41:25 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,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 104BE2AE54 for ; Sat, 1 Sep 2018 07:41:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727064AbeIALw0 (ORCPT ); Sat, 1 Sep 2018 07:52:26 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36090 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbeIALw0 (ORCPT ); Sat, 1 Sep 2018 07:52:26 -0400 Received: by mail-wr1-f67.google.com with SMTP id m27-v6so13109094wrf.3 for ; Sat, 01 Sep 2018 00:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T+rdeo1clGb/LKhNG6HPbZCnbGmIVx1dBkD8O418t5g=; b=MFqNJdbwrwSbh5MH5EkT262oF/z02zNXUrwjuIfmP954VAhk2yT7uG+GLZP1kzku8M 5xMhylmXSfHhiEe7DiWts4lZdoExzkYqne+1mMlt2b6ALpNd4siWZMyn756oCj/c6Evw VQBnV73EvVWNk/PaOwXLrQjLLyHK4lYwRhySpTTCsrFlot98PnbsyRfsCeHWVl2BV+xI VNRtPzr+karFqvESz0tfEHsQbS2GUPNBs46Dur+dSoNnIKQqBL2lb2yQegwNpSnih4Ka MLXK/KBCA/A4PVHDYnHLAyPdgjpZzKBC9Pvw3b+tgiOyS0VBI7k5s8y4zezBFSM3mR2t geqw== 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=T+rdeo1clGb/LKhNG6HPbZCnbGmIVx1dBkD8O418t5g=; b=fujDmCvKo5piwecGPsJv0u14vTirzWQn3JtcLYVLqYylvNzBAkHHxZmqVlNwj3/fEC R0RRH9InDFY8UErKY5p58qtRyu/YGRoN47DKl7n6pwRBcMs6uZwPA8aabUFtb6yFNuce 4QRKR0Svh9LaBg3RXXqlvq0oqJZk6OyeCeCREPF2mWv6eUUXLDMFy7En7Mn8KX7KQdhs J/KdTrSXeIDk3jYoBozr6Bp67BzBbOTcj3ydpWX++3C2TVZ++P1Yp/oiQdwCuufZ1oHA wZVI3wxseevi4B6R4S0byzU1hj08JUhbb/I2v6pjVnDcug70xKx4VbD5+qHUmmVHzacB pw/g== X-Gm-Message-State: APzg51DYEb5xOenSO/53yE0uQ/DFjqp/SLkcv7pgr/rlu5fEdAufft3g 8ZtF5xDLziKiawQMHomdcqk= X-Google-Smtp-Source: ANB0VdZ0JXAZUaB//5thO1gHuICS5d7OsXnXwxBTw+2qbUFmTSug3wOPdGSOwCY3V8iEZoEScaTMGQ== X-Received: by 2002:a5d:68c9:: with SMTP id p9-v6mr12970413wrw.108.1535787681739; Sat, 01 Sep 2018 00:41:21 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.68]) by smtp.gmail.com with ESMTPSA id u40-v6sm21774386wrc.43.2018.09.01.00.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 00:41:21 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Marko Rauhamaa , linux-fsdevel@vger.kernel.org Subject: [PATCH v4 1/3] fsnotify: add super block object type Date: Sat, 1 Sep 2018 10:41:11 +0300 Message-Id: <20180901074113.32296-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180901074113.32296-1-amir73il@gmail.com> References: <20180901074113.32296-1-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 the infrastructure to attach a mark to a super_block struct and detach all attached marks when super block is destroyed. This is going to be used by fanotify backend to setup super block marks. Signed-off-by: Amir Goldstein --- fs/notify/fdinfo.c | 5 +++++ fs/notify/fsnotify.c | 8 +++++++- fs/notify/fsnotify.h | 11 +++++++++++ fs/notify/mark.c | 4 ++++ fs/super.c | 2 +- include/linux/fs.h | 5 +++++ include/linux/fsnotify_backend.h | 17 ++++++++++++++--- 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 86fcf5814279..25385e336ac7 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -131,6 +131,11 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n", mnt->mnt_id, mflags, mark->mask, mark->ignored_mask); + } else if (mark->connector->type == FSNOTIFY_OBJ_TYPE_SB) { + struct super_block *sb = fsnotify_conn_sb(mark->connector); + + seq_printf(m, "fanotify sdev:%x mflags:%x mask:%x ignored_mask:%x\n", + sb->s_dev, mflags, mark->mask, mark->ignored_mask); } } diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index ababdbfab537..2971803d151c 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -48,7 +48,7 @@ void __fsnotify_vfsmount_delete(struct vfsmount *mnt) * Called during unmount with no locks held, so needs to be safe against * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block. */ -void fsnotify_unmount_inodes(struct super_block *sb) +static void fsnotify_unmount_inodes(struct super_block *sb) { struct inode *inode, *iput_inode = NULL; @@ -98,6 +98,12 @@ void fsnotify_unmount_inodes(struct super_block *sb) iput(iput_inode); } +void fsnotify_sb_delete(struct super_block *sb) +{ + fsnotify_unmount_inodes(sb); + fsnotify_clear_marks_by_sb(sb); +} + /* * Given an inode, first check if we care what happens to our children. Inotify * and dnotify both tell their parents about events. If we care about any event diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h index 7902653dd577..5a00121fb219 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h @@ -21,6 +21,12 @@ static inline struct mount *fsnotify_conn_mount( return container_of(conn->obj, struct mount, mnt_fsnotify_marks); } +static inline struct super_block *fsnotify_conn_sb( + struct fsnotify_mark_connector *conn) +{ + return container_of(conn->obj, struct super_block, s_fsnotify_marks); +} + /* destroy all events sitting in this groups notification queue */ extern void fsnotify_flush_notify(struct fsnotify_group *group); @@ -43,6 +49,11 @@ static inline void fsnotify_clear_marks_by_mount(struct vfsmount *mnt) { fsnotify_destroy_marks(&real_mount(mnt)->mnt_fsnotify_marks); } +/* run the list of all marks associated with sb and destroy them */ +static inline void fsnotify_clear_marks_by_sb(struct super_block *sb) +{ + fsnotify_destroy_marks(&sb->s_fsnotify_marks); +} /* Wait until all marks queued for destruction are destroyed */ extern void fsnotify_wait_marks_destroyed(void); diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 59cdb27826de..b5172ccb2e60 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -115,6 +115,8 @@ static __u32 *fsnotify_conn_mask_p(struct fsnotify_mark_connector *conn) return &fsnotify_conn_inode(conn)->i_fsnotify_mask; else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) return &fsnotify_conn_mount(conn)->mnt_fsnotify_mask; + else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) + return &fsnotify_conn_sb(conn)->s_fsnotify_mask; return NULL; } @@ -192,6 +194,8 @@ static struct inode *fsnotify_detach_connector_from_object( inode->i_fsnotify_mask = 0; } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; + } else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) { + fsnotify_conn_sb(conn)->s_fsnotify_mask = 0; } rcu_assign_pointer(*(conn->obj), NULL); diff --git a/fs/super.c b/fs/super.c index f3a8c008e164..ca53a08497ed 100644 --- a/fs/super.c +++ b/fs/super.c @@ -442,7 +442,7 @@ void generic_shutdown_super(struct super_block *sb) sync_filesystem(sb); sb->s_flags &= ~SB_ACTIVE; - fsnotify_unmount_inodes(sb); + fsnotify_sb_delete(sb); cgroup_writeback_umount(); evict_inodes(sb); diff --git a/include/linux/fs.h b/include/linux/fs.h index 6c0b4a1c22ff..4f0a11d0d296 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1464,6 +1464,11 @@ struct super_block { spinlock_t s_inode_wblist_lock; struct list_head s_inodes_wb; /* writeback inodes */ + +#ifdef CONFIG_FSNOTIFY + __u32 s_fsnotify_mask; + struct fsnotify_mark_connector __rcu *s_fsnotify_marks; +#endif } __randomize_layout; /* Helper functions so that in most cases filesystems will diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index b8f4182f42f1..81b88fc9df31 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -206,12 +206,14 @@ struct fsnotify_group { enum fsnotify_obj_type { FSNOTIFY_OBJ_TYPE_INODE, FSNOTIFY_OBJ_TYPE_VFSMOUNT, + FSNOTIFY_OBJ_TYPE_SB, FSNOTIFY_OBJ_TYPE_COUNT, FSNOTIFY_OBJ_TYPE_DETACHED = FSNOTIFY_OBJ_TYPE_COUNT }; #define FSNOTIFY_OBJ_TYPE_INODE_FL (1U << FSNOTIFY_OBJ_TYPE_INODE) #define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT) +#define FSNOTIFY_OBJ_TYPE_SB_FL (1U << FSNOTIFY_OBJ_TYPE_SB) #define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1) static inline bool fsnotify_valid_obj_type(unsigned int type) @@ -255,6 +257,7 @@ static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \ FSNOTIFY_ITER_FUNCS(inode, INODE) FSNOTIFY_ITER_FUNCS(vfsmount, VFSMOUNT) +FSNOTIFY_ITER_FUNCS(sb, SB) #define fsnotify_foreach_obj_type(type) \ for (type = 0; type < FSNOTIFY_OBJ_TYPE_COUNT; type++) @@ -267,8 +270,8 @@ struct fsnotify_mark_connector; typedef struct fsnotify_mark_connector __rcu *fsnotify_connp_t; /* - * Inode / vfsmount point to this structure which tracks all marks attached to - * the inode / vfsmount. The reference to inode / vfsmount is held by this + * Inode/vfsmount/sb point to this structure which tracks all marks attached to + * the inode/vfsmount/sb. The reference to inode/vfsmount/sb is held by this * structure. We destroy this structure when there are no more marks attached * to it. The structure is protected by fsnotify_mark_srcu. */ @@ -335,6 +338,7 @@ extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int dat extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask); extern void __fsnotify_inode_delete(struct inode *inode); extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); +extern void fsnotify_sb_delete(struct super_block *sb); extern u32 fsnotify_get_cookie(void); static inline int fsnotify_inode_watches_children(struct inode *inode) @@ -455,9 +459,13 @@ static inline void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *gr { fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_INODE_FL); } +/* run all the marks in a group, and clear all of the sn marks */ +static inline void fsnotify_clear_sb_marks_by_group(struct fsnotify_group *group) +{ + fsnotify_clear_marks_by_group(group, FSNOTIFY_OBJ_TYPE_SB_FL); +} extern void fsnotify_get_mark(struct fsnotify_mark *mark); extern void fsnotify_put_mark(struct fsnotify_mark *mark); -extern void fsnotify_unmount_inodes(struct super_block *sb); extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info); extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info); @@ -484,6 +492,9 @@ static inline void __fsnotify_inode_delete(struct inode *inode) static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt) {} +static inline void fsnotify_sb_delete(struct super_block *sb) +{} + static inline void fsnotify_update_flags(struct dentry *dentry) {} From patchwork Sat Sep 1 07:41:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10584637 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 8DDA917DB for ; Sat, 1 Sep 2018 07:41:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D8562AE54 for ; Sat, 1 Sep 2018 07:41:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 720BB2AE77; Sat, 1 Sep 2018 07:41:26 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,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 126FE2AE54 for ; Sat, 1 Sep 2018 07:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbeIALw1 (ORCPT ); Sat, 1 Sep 2018 07:52:27 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37060 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725964AbeIALw1 (ORCPT ); Sat, 1 Sep 2018 07:52:27 -0400 Received: by mail-wr1-f68.google.com with SMTP id u12-v6so13085232wrr.4 for ; Sat, 01 Sep 2018 00:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8kk9o6h71I+kfRszgX/m0BWt8O5vBg2fomasbuy5gfA=; b=VGXWHqFyqVE7j7EvaZ40ihHmTdedDBBusD/9qWX5Q+ig+N8kdIyhSOc0dIIRIUPVnU dewfasQBOA9Bpf52JJ2zMvT2caL8pH5sywBRdfKn2fvfxJ0FXT+F6oTkDAn1aLoh1xZX 8+aVUk1oMYI1T69+EKMfXyJbxj0CDXeG+NxRVOcl+Lj+m8/a31leMW/COYs8Q1uxlkUi 57+SKCEuSnL3cvF9ETwsVqHyaNSFdUajz/oJhBAETqgaSEK7+aYbpFwbjXbWgB0Lj87g 6vM6sBuC2CDOwebnpkfEeIV0urlacGPhzy52grnYcmbFurYD1zYKUFJWOQN+qQlG14kW /PYQ== 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=8kk9o6h71I+kfRszgX/m0BWt8O5vBg2fomasbuy5gfA=; b=tZwIShzDB4IM4LNxA8QwrWGelWtlYEwRzH/IrQ41J3MXNhzOE6E1l796Y3Q4UIhkcO mBeUfvrqmrFYbGbQt02kblDbd9mZ36vomxESJU1LSd8h488/iP/bfor2csO6cA/Lok3k 9o57HjCHTzmClNXYHbW50f2JHmkAWtoMQgzjtK7nhdKlkmWOU0f24uBG1D+iUQwqRN2C LmduM+P3vs44bfjCW8eKE5+2IK7ardo97LKkdaeXGDpAgE99fOh5TPr3DLl9LjexRbR8 ovUmh7JX+5Hnl8AqnVBU9rnbOdOmqAJI/cs4G4tdMi+p89luvRlZRYC9KrTxGHQPcSVf HLZg== X-Gm-Message-State: APzg51AanT/5PK/uRAShLCCz1yNy1cXVRNUqiev6KX7Usjk5x0RhCoj0 ErGJUxTCL3FOghEpRJOnKpw= X-Google-Smtp-Source: ANB0VdaVDy15rcoKfrMfgf+tsekSIx2J4xhEVKO7xuvnXbw+emSM8YvWMMNMY/kmP211uaJdS8lxww== X-Received: by 2002:adf:bd10:: with SMTP id j16-v6mr13068223wrh.267.1535787682949; Sat, 01 Sep 2018 00:41:22 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.68]) by smtp.gmail.com with ESMTPSA id u40-v6sm21774386wrc.43.2018.09.01.00.41.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 00:41:22 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Marko Rauhamaa , linux-fsdevel@vger.kernel.org Subject: [PATCH v4 2/3] fsnotify: send path type events to group with super block marks Date: Sat, 1 Sep 2018 10:41:12 +0300 Message-Id: <20180901074113.32296-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180901074113.32296-1-amir73il@gmail.com> References: <20180901074113.32296-1-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 Send events to group if super block mark mask matches the event and unless the same group has an ignore mask on the vfsmount or the inode on which the event occurred. Soon, fanotify backend is going to support super block marks and fanotify backend only supports path type events. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 2971803d151c..422fbc6dffde 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -325,15 +325,18 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, const unsigned char *file_name, u32 cookie) { struct fsnotify_iter_info iter_info = {}; - struct mount *mnt; + struct super_block *sb = NULL; + struct mount *mnt = NULL; + __u32 mnt_or_sb_mask = 0; int ret = 0; /* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); - if (data_is == FSNOTIFY_EVENT_PATH) + if (data_is == FSNOTIFY_EVENT_PATH) { mnt = real_mount(((const struct path *)data)->mnt); - else - mnt = NULL; + sb = mnt->mnt.mnt_sb; + mnt_or_sb_mask = mnt->mnt_fsnotify_mask | sb->s_fsnotify_mask; + } /* * Optimization: srcu_read_lock() has a memory barrier which can @@ -343,16 +346,15 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, * need SRCU to keep them "alive". */ if (!to_tell->i_fsnotify_marks && - (!mnt || !mnt->mnt_fsnotify_marks)) + (!mnt || (!mnt->mnt_fsnotify_marks && !sb->s_fsnotify_marks))) return 0; /* * if this is a modify event we may need to clear the ignored masks - * otherwise return if neither the inode nor the vfsmount care about + * otherwise return if neither the inode nor the vfsmount/sb care about * this type of event. */ if (!(mask & FS_MODIFY) && - !(test_mask & to_tell->i_fsnotify_mask) && - !(mnt && test_mask & mnt->mnt_fsnotify_mask)) + !(test_mask & (to_tell->i_fsnotify_mask | mnt_or_sb_mask))) return 0; iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); @@ -362,11 +364,13 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, if (mnt) { iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = fsnotify_first_mark(&mnt->mnt_fsnotify_marks); + iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = + fsnotify_first_mark(&sb->s_fsnotify_marks); } /* - * We need to merge inode & vfsmount mark lists so that inode mark - * ignore masks are properly reflected for mount mark notifications. + * We need to merge inode/vfsmount/sb mark lists so that e.g. inode mark + * ignore masks are properly reflected for mount/sb mark notifications. * That's why this traversal is so complicated... */ while (fsnotify_iter_select_report_types(&iter_info)) { From patchwork Sat Sep 1 07:41:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10584639 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 90596174A for ; Sat, 1 Sep 2018 07:41:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F3562AE54 for ; Sat, 1 Sep 2018 07:41:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 739062AE77; Sat, 1 Sep 2018 07:41:28 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,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 E5A302AE54 for ; Sat, 1 Sep 2018 07:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbeIALw3 (ORCPT ); Sat, 1 Sep 2018 07:52:29 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44581 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbeIALw3 (ORCPT ); Sat, 1 Sep 2018 07:52:29 -0400 Received: by mail-wr1-f67.google.com with SMTP id v16-v6so13103311wro.11; Sat, 01 Sep 2018 00:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K8V42tJ2//OJiasZuZw6AoBRnffyPotoEgoTPNIPM3k=; b=ApZqpg9df5k4iGlQMWSYsfh12ic+9r3ZUKoEpb8FLYKHUbSS22MoHWH/DRyE8zJJ1M 3QORsEzlx5jD6Vwp9WjW1laiaIN/1IL8CRP2hFbSRBHzdoACIfKggxcRBs6zG7XA4vhi TCc2QA1DSKStRvI8HE6o8hv/4YFlvDLqyDfc6encRKjmn13t4IMyblQ5Pk0wKMUlmfK8 hRT+meN3uWCQXzYbcWIzIO3yQtxN5LEi6JTM6rjT577EjNS4GxcgKpmKeQwQSFVLygAE 5TRulMvtcapbr/YcbLWL5WxkInWJq7WzNxw3Vt/miIPYs+W6mVweK5MQHkNSPsx3zFGl ioZg== 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=K8V42tJ2//OJiasZuZw6AoBRnffyPotoEgoTPNIPM3k=; b=MBjqJzoZXwFYUZi7uI/mFy8pyaP0+8T4MbW2fHZ2cbf/b7I0PIfzofBtJjpNdjW7ZD EsFKBq/iMPtoPR8gijb76/Wry3JNR04VhCJQ8rwNYsAn1qZ80fHeXbZj3tgqNXR69d3x OIxeo3SX4zljJNwgKNKU+lrCoUMBOZKclgHSBe7RoIVBPbIEjUXrSrOk+rS2o9ObWe1I fPYjpQKSjVc/KzBxBkU/t5GSlS8GLAu4Mf1fCqnylKUcSISaoLmUFNy8rrUhLJUSo+cf 584jFGEzroBiOPNnNZOVFb3GMSaZBXtN2TVXROFx08nz5D5YfPIQWfnRrHP+5LNldvn/ Ut1g== X-Gm-Message-State: APzg51CouDNY3PX7ze9JL73DaQKIa6eSTBNBRBwYARltz8lV9k75wqhh UzIcIcx38OJE+kS2sAE20KU= X-Google-Smtp-Source: ANB0VdZMuvVEgs8FRQTAs84+OfWgETJJM/i9QrkX9QZzok7l+7Xi2/7dqTgROhje5dDmEvzZCQy9Hg== X-Received: by 2002:adf:9b11:: with SMTP id b17-v6mr13897710wrc.119.1535787684213; Sat, 01 Sep 2018 00:41:24 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.68]) by smtp.gmail.com with ESMTPSA id u40-v6sm21774386wrc.43.2018.09.01.00.41.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 00:41:23 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Marko Rauhamaa , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v4 3/3] fanotify: add API to attach/detach super block mark Date: Sat, 1 Sep 2018 10:41:13 +0300 Message-Id: <20180901074113.32296-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180901074113.32296-1-amir73il@gmail.com> References: <20180901074113.32296-1-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 another mark type flag FAN_MARK_FILESYSTEM for add/remove/flush of super block mark type. A super block watch gets all events on the filesystem, regardless of the mount from which the mark was added, unless an ignore mask exists on either the inode or the mount where the event was generated. Only one of FAN_MARK_MOUNT and FAN_MARK_FILESYSTEM mark type flags may be provided to fanotify_mark() or no mark type flag for inode mark. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 42 ++++++++++++++++++++++++++---- include/uapi/linux/fanotify.h | 12 ++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 69054886915b..1347c588f778 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -563,6 +563,13 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, mask, flags); } +static int fanotify_remove_sb_mark(struct fsnotify_group *group, + struct super_block *sb, __u32 mask, + unsigned int flags) +{ + return fanotify_remove_mark(group, &sb->s_fsnotify_marks, mask, flags); +} + static int fanotify_remove_inode_mark(struct fsnotify_group *group, struct inode *inode, __u32 mask, unsigned int flags) @@ -658,6 +665,14 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, FSNOTIFY_OBJ_TYPE_VFSMOUNT, mask, flags); } +static int fanotify_add_sb_mark(struct fsnotify_group *group, + struct super_block *sb, __u32 mask, + unsigned int flags) +{ + return fanotify_add_mark(group, &sb->s_fsnotify_marks, + FSNOTIFY_OBJ_TYPE_SB, mask, flags); +} + static int fanotify_add_inode_mark(struct fsnotify_group *group, struct inode *inode, __u32 mask, unsigned int flags) @@ -806,6 +821,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, struct fd f; struct path path; u32 valid_mask = FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD; + unsigned int mark_type = flags & FAN_MARK_TYPE_MASK; int ret; pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", @@ -817,6 +833,16 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (flags & ~FAN_ALL_MARK_FLAGS) return -EINVAL; + + switch (mark_type) { + case FAN_MARK_INODE: + case FAN_MARK_MOUNT: + case FAN_MARK_FILESYSTEM: + break; + default: + return -EINVAL; + } + switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_FLUSH)) { case FAN_MARK_ADD: /* fallthrough */ case FAN_MARK_REMOVE: @@ -824,7 +850,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, return -EINVAL; break; case FAN_MARK_FLUSH: - if (flags & ~(FAN_MARK_MOUNT | FAN_MARK_FLUSH)) + if (flags & ~(FAN_MARK_TYPE_MASK | FAN_MARK_FLUSH)) return -EINVAL; break; default: @@ -863,8 +889,10 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (flags & FAN_MARK_FLUSH) { ret = 0; - if (flags & FAN_MARK_MOUNT) + if (mark_type == FAN_MARK_MOUNT) fsnotify_clear_vfsmount_marks_by_group(group); + else if (mark_type == FAN_MARK_FILESYSTEM) + fsnotify_clear_sb_marks_by_group(group); else fsnotify_clear_inode_marks_by_group(group); goto fput_and_out; @@ -875,7 +903,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, goto fput_and_out; /* inode held in place by reference to path; group by fget on fd */ - if (!(flags & FAN_MARK_MOUNT)) + if (mark_type == FAN_MARK_INODE) inode = path.dentry->d_inode; else mnt = path.mnt; @@ -883,14 +911,18 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, /* create/update an inode mark */ switch (flags & (FAN_MARK_ADD | FAN_MARK_REMOVE)) { case FAN_MARK_ADD: - if (flags & FAN_MARK_MOUNT) + if (mark_type == FAN_MARK_MOUNT) ret = fanotify_add_vfsmount_mark(group, mnt, mask, flags); + else if (mark_type == FAN_MARK_FILESYSTEM) + ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask, flags); else ret = fanotify_add_inode_mark(group, inode, mask, flags); break; case FAN_MARK_REMOVE: - if (flags & FAN_MARK_MOUNT) + if (mark_type == FAN_MARK_MOUNT) ret = fanotify_remove_vfsmount_mark(group, mnt, mask, flags); + else if (mark_type == FAN_MARK_FILESYSTEM) + ret = fanotify_remove_sb_mark(group, mnt->mnt_sb, mask, flags); else ret = fanotify_remove_inode_mark(group, inode, mask, flags); break; diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 74247917de04..e94ae2b34f3b 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -47,19 +47,25 @@ #define FAN_MARK_REMOVE 0x00000002 #define FAN_MARK_DONT_FOLLOW 0x00000004 #define FAN_MARK_ONLYDIR 0x00000008 -#define FAN_MARK_MOUNT 0x00000010 #define FAN_MARK_IGNORED_MASK 0x00000020 #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 #define FAN_MARK_FLUSH 0x00000080 +/* These are NOT bitwise flags. Both bits can be used togther. */ +#define FAN_MARK_INODE 0x00000000 +#define FAN_MARK_MOUNT 0x00000010 +#define FAN_MARK_FILESYSTEM 0x00000100 +#define FAN_MARK_TYPE_MASK (FAN_MARK_INODE | FAN_MARK_MOUNT | \ + FAN_MARK_FILESYSTEM) + #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ FAN_MARK_REMOVE |\ FAN_MARK_DONT_FOLLOW |\ FAN_MARK_ONLYDIR |\ - FAN_MARK_MOUNT |\ FAN_MARK_IGNORED_MASK |\ FAN_MARK_IGNORED_SURV_MODIFY |\ - FAN_MARK_FLUSH) + FAN_MARK_FLUSH|\ + FAN_MARK_TYPE_MASK) /* * All of the events - we build the list by hand so that we can add flags in