From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 10/13] fsnotify: pass object and object type to fsnotify_add_mark()
Date: Fri, 20 Apr 2018 16:10:58 -0700 [thread overview]
Message-ID: <1524265861-6316-11-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1524265861-6316-1-git-send-email-amir73il@gmail.com>
Instead of passing inode and vfsmount arguments to fsnotify_add_mark()
and its _locked variant, pass an abstract fsnotify_obj and the object
type.
This is going to be used for adding a mark to a new type of object
(super block object).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/fanotify/fanotify_user.c | 16 ++++++++-------
fs/notify/mark.c | 42 +++++++++++++++-----------------------
include/linux/fsnotify_backend.h | 18 +++++++++++-----
3 files changed, 39 insertions(+), 37 deletions(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index c15de35c3ebc..42ec185be089 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -614,8 +614,8 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
}
static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
- struct inode *inode,
- struct vfsmount *mnt)
+ struct fsnotify_obj *obj,
+ unsigned int type)
{
struct fsnotify_mark *mark;
int ret;
@@ -628,7 +628,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
return ERR_PTR(-ENOMEM);
fsnotify_init_mark(mark, group);
- ret = fsnotify_add_mark_locked(mark, inode, mnt, 0);
+ ret = fsnotify_add_mark_locked(mark, obj, type, 0);
if (ret) {
fsnotify_put_mark(mark);
return ERR_PTR(ret);
@@ -642,13 +642,14 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group,
struct vfsmount *mnt, __u32 mask,
unsigned int flags)
{
+ struct fsnotify_obj *obj = &real_mount(mnt)->mnt_fsnotify;
struct fsnotify_mark *fsn_mark;
__u32 added;
mutex_lock(&group->mark_mutex);
- fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify, group);
+ fsn_mark = fsnotify_find_mark(obj, group);
if (!fsn_mark) {
- fsn_mark = fanotify_add_new_mark(group, NULL, mnt);
+ fsn_mark = fanotify_add_new_mark(group, obj, FSNOTIFY_OBJ_TYPE_VFSMOUNT);
if (IS_ERR(fsn_mark)) {
mutex_unlock(&group->mark_mutex);
return PTR_ERR(fsn_mark);
@@ -667,6 +668,7 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
struct inode *inode, __u32 mask,
unsigned int flags)
{
+ struct fsnotify_obj *obj = &inode->i_fsnotify;
struct fsnotify_mark *fsn_mark;
__u32 added;
@@ -683,9 +685,9 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group,
return 0;
mutex_lock(&group->mark_mutex);
- fsn_mark = fsnotify_find_mark(&inode->i_fsnotify, group);
+ fsn_mark = fsnotify_find_mark(obj, group);
if (!fsn_mark) {
- fsn_mark = fanotify_add_new_mark(group, inode, NULL);
+ fsn_mark = fanotify_add_new_mark(group, obj, FSNOTIFY_OBJ_TYPE_INODE);
if (IS_ERR(fsn_mark)) {
mutex_unlock(&group->mark_mutex);
return PTR_ERR(fsn_mark);
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 2cd2a872bd66..771178c46eeb 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -437,9 +437,9 @@ int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
}
static int fsnotify_attach_connector_to_object(struct fsnotify_obj *obj,
- struct inode *inode,
- struct vfsmount *mnt)
+ unsigned int type)
{
+ struct inode *inode = NULL;
struct fsnotify_mark_connector *conn;
conn = kmem_cache_alloc(fsnotify_mark_connector_cachep, GFP_KERNEL);
@@ -447,13 +447,11 @@ static int fsnotify_attach_connector_to_object(struct fsnotify_obj *obj,
return -ENOMEM;
spin_lock_init(&conn->lock);
INIT_HLIST_HEAD(&conn->list);
- if (inode) {
- conn->type = FSNOTIFY_OBJ_TYPE_INODE;
- conn->inode = igrab(inode);
- } else {
- conn->type = FSNOTIFY_OBJ_TYPE_VFSMOUNT;
- conn->mnt = mnt;
- }
+ conn->type = type;
+ if (conn->type == FSNOTIFY_OBJ_TYPE_INODE)
+ inode = conn->inode = igrab(fsnotify_obj_inode(obj));
+ else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT)
+ conn->mnt = &fsnotify_obj_mount(obj)->mnt;
/*
* cmpxchg() provides the barrier so that readers of obj->marks can see
* only initialized structure
@@ -502,27 +500,22 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector(
* priority, highest number first, and then by the group's location in memory.
*/
static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
- struct inode *inode, struct vfsmount *mnt,
+ struct fsnotify_obj *obj, unsigned int type,
int allow_dups)
{
struct fsnotify_mark *lmark, *last = NULL;
struct fsnotify_mark_connector *conn;
- struct fsnotify_obj *obj;
int cmp;
int err = 0;
- if (WARN_ON(!inode && !mnt))
+ if (WARN_ON(!fsnotify_valid_obj_type(type)))
return -EINVAL;
- if (inode)
- obj = &inode->i_fsnotify;
- else
- obj = &real_mount(mnt)->mnt_fsnotify;
restart:
spin_lock(&mark->lock);
conn = fsnotify_grab_connector(obj);
if (!conn) {
spin_unlock(&mark->lock);
- err = fsnotify_attach_connector_to_object(obj, inode, mnt);
+ err = fsnotify_attach_connector_to_object(obj, type);
if (err)
return err;
goto restart;
@@ -568,14 +561,13 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,
* These marks may be used for the fsnotify backend to determine which
* event types should be delivered to which group.
*/
-int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
- struct vfsmount *mnt, int allow_dups)
+int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
+ struct fsnotify_obj *obj, unsigned int type,
+ int allow_dups)
{
struct fsnotify_group *group = mark->group;
int ret = 0;
- BUG_ON(inode && mnt);
- BUG_ON(!inode && !mnt);
BUG_ON(!mutex_is_locked(&group->mark_mutex));
/*
@@ -592,7 +584,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
fsnotify_get_mark(mark); /* for g_list */
spin_unlock(&mark->lock);
- ret = fsnotify_add_mark_list(mark, inode, mnt, allow_dups);
+ ret = fsnotify_add_mark_list(mark, obj, type, allow_dups);
if (ret)
goto err;
@@ -612,14 +604,14 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode,
return ret;
}
-int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
- struct vfsmount *mnt, int allow_dups)
+int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_obj *obj,
+ unsigned int type, int allow_dups)
{
int ret;
struct fsnotify_group *group = mark->group;
mutex_lock(&group->mark_mutex);
- ret = fsnotify_add_mark_locked(mark, inode, mnt, allow_dups);
+ ret = fsnotify_add_mark_locked(mark, obj, type, allow_dups);
mutex_unlock(&group->mark_mutex);
return ret;
}
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 15ea4661995d..b2826dd1e68c 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -211,6 +211,11 @@ enum fsnotify_obj_type {
#define FSNOTIFY_OBJ_TYPE_VFSMOUNT_FL (1U << FSNOTIFY_OBJ_TYPE_VFSMOUNT)
#define FSNOTIFY_OBJ_ALL_TYPES_MASK ((1U << FSNOTIFY_OBJ_TYPE_COUNT) - 1)
+static inline bool fsnotify_valid_obj_type(unsigned int type)
+{
+ return (type < FSNOTIFY_OBJ_TYPE_COUNT);
+}
+
struct fsnotify_iter_info {
struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_COUNT];
unsigned int report_mask;
@@ -403,23 +408,26 @@ extern void fsnotify_init_mark(struct fsnotify_mark *mark,
extern struct fsnotify_mark *fsnotify_find_mark(struct fsnotify_obj *obj,
struct fsnotify_group *group);
/* attach the mark to the inode or vfsmount */
-extern int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode,
- struct vfsmount *mnt, int allow_dups);
+extern int fsnotify_add_mark(struct fsnotify_mark *mark,
+ struct fsnotify_obj *obj, unsigned int type,
+ int allow_dups);
extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
- struct inode *inode, struct vfsmount *mnt,
+ struct fsnotify_obj *obj, unsigned int type,
int allow_dups);
/* attach the mark to the inode */
static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
struct inode *inode,
int allow_dups)
{
- return fsnotify_add_mark(mark, inode, NULL, allow_dups);
+ return fsnotify_add_mark(mark, &inode->i_fsnotify,
+ FSNOTIFY_OBJ_TYPE_INODE, allow_dups);
}
static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark,
struct inode *inode,
int allow_dups)
{
- return fsnotify_add_mark_locked(mark, inode, NULL, allow_dups);
+ return fsnotify_add_mark_locked(mark, &inode->i_fsnotify,
+ FSNOTIFY_OBJ_TYPE_INODE, allow_dups);
}
/* given a group and a mark, flag mark to be freed when all references are dropped */
extern void fsnotify_destroy_mark(struct fsnotify_mark *mark,
--
2.7.4
next prev parent reply other threads:[~2018-04-20 23:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 23:10 [PATCH v3 00/13] Preparing for fanotify super block marks Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 01/13] fsnotify: use type id to identify connector object type Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 02/13] fsnotify: remove redundant arguments to handle_event() Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 03/13] fsnotify: introduce marks iteration helpers Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 04/13] fsnotify: generalize iteration of marks by object type Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 05/13] fsnotify: generalize send_to_group() Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 06/13] fanotify: generalize fanotify_should_send_event() Amir Goldstein
2018-05-18 10:47 ` Jan Kara
2018-04-20 23:10 ` [PATCH v3 07/13] fsnotify: add fsnotify_add_inode_mark() wrappers Amir Goldstein
2018-04-20 23:10 ` [PATCH v3 08/13] fsnotify: introduce prototype struct fsnotify_obj Amir Goldstein
2018-05-18 12:02 ` Jan Kara
2018-04-20 23:10 ` [PATCH v3 09/13] fsnotify: pass fsnotify_obj instead of **connp argument Amir Goldstein
2018-04-20 23:10 ` Amir Goldstein [this message]
2018-04-20 23:10 ` [PATCH v3 11/13] fsnotify: add fsnotify_connector_inode() wrapper Amir Goldstein
2018-05-18 12:48 ` Jan Kara
2018-04-20 23:11 ` [PATCH v3 12/13] fsnotify: let connector point to abstract fsnotify_obj Amir Goldstein
2018-04-20 23:11 ` [PATCH v3 13/13] fanotify: factor out helpers to add/remove mark Amir Goldstein
2018-05-18 13:09 ` [PATCH v3 00/13] Preparing for fanotify super block marks Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524265861-6316-11-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).