From patchwork Thu Apr 5 13:18:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10324605 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 4DD0C600CB for ; Thu, 5 Apr 2018 13:18:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FAAE2785D for ; Thu, 5 Apr 2018 13:18:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 339DC27EE2; Thu, 5 Apr 2018 13:18:04 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 664A429147 for ; Thu, 5 Apr 2018 13:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751743AbeDENRs (ORCPT ); Thu, 5 Apr 2018 09:17:48 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38026 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbeDENRZ (ORCPT ); Thu, 5 Apr 2018 09:17:25 -0400 Received: by mail-wm0-f68.google.com with SMTP id i3so6997365wmf.3 for ; Thu, 05 Apr 2018 06:17: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=1dxC4s+66q67a7q2sXuVovl1zbtoRkZ6IWQ1FW+gLJw=; b=YRovldN17gvDKqNI3aI7ywedGEorxrGWAvPVYXFoD4UHyybl2FNJScwFnudcO0ouo6 pKZtOmzzHiatWg9w+qU1C1yKOQmZy2nOToQ2ojHk6RslBoh0xL+gsKXFPZxptF9nxnyM MGtOpJXFleb5n2Zm9ydIKbmMezYNgH7BH7socNnpyNJpF8cAks9HVnZTDibCrNsDZmoE ezddgFW4IWs2rv/3x0IB5THM9D9BJJqbVQlCSvx7yJI67A+uRb9qDxN60+xiRkezToNp MnX4J4f+2ka6bm3wlpaRMtqirpUs4s/+/fnJmqLrMlXtK5lPYpbk6VRBNsm+5AvxipQl FRYw== 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=1dxC4s+66q67a7q2sXuVovl1zbtoRkZ6IWQ1FW+gLJw=; b=Mp9l/ZYEUlfFR6LhqaS+WX3RrGhpSIzQzw0n2tGThBu3Y3snS9gP/uuyEr/vXzfMTg h4HvhSTv3MKJHsnFSaaLxoJY6Xggd6lc2YzQnLYM1+lG8CPBGWWF8GlajZ8fUxcha8x2 aoWLpa74KKmm1tVydkedtZ4dhr2Uc56k/paHjYoNUY+c+rvvVO1wI7l3Zg1GXFiHzebE kftBY0/NqmMsOjGS3/HgoPInTuEKQpp+GJEfbV1KUTwJ26iqvS/H1cFMIphqgTyT/BNx niJVVy8IAmPT6XW5wziFUv4ZSAJ7loeBwOFVPkF9s02EWo5cFmWs/LBROQapLF+3VNLq kNlg== X-Gm-Message-State: ALQs6tCIkfKtcBW8TrH1gUPEofYUYoNSj1FVI/wvmB0etRQPQY682fMI J+vPvRDBxLHmU98thr1fWZM= X-Google-Smtp-Source: AIpwx4+Qsc1m7Te5bDDvNbxOA3gb7/eIJUkZVmEszFxPMuGPvFqU6Y8jbUI/lu1RV71e2iXlflAo+Q== X-Received: by 10.28.14.9 with SMTP id 9mr9755744wmo.127.1522934243620; Thu, 05 Apr 2018 06:17:23 -0700 (PDT) Received: from localhost.localdomain ([141.226.13.13]) by smtp.gmail.com with ESMTPSA id p197sm3108398wme.43.2018.04.05.06.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 06:17:23 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Miklos Szeredi , Marko Rauhamaa , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 14/20] fsnotify: pass object and object type to fsnotify_add_mark() Date: Thu, 5 Apr 2018 16:18:15 +0300 Message-Id: <1522934301-6520-15-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522934301-6520-1-git-send-email-amir73il@gmail.com> References: <1522934301-6520-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 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 --- fs/notify/fanotify/fanotify_user.c | 16 ++++++++------- fs/notify/fsnotify.h | 11 ++++++++++ fs/notify/mark.c | 42 +++++++++++++++----------------------- include/linux/fsnotify_backend.h | 18 +++++++++++----- 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8da861cb3f5c..ecd3539587cc 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/fsnotify.h b/fs/notify/fsnotify.h index 6459481c964f..2a3fe62e2bf6 100644 --- a/fs/notify/fsnotify.h +++ b/fs/notify/fsnotify.h @@ -44,4 +44,15 @@ extern void __fsnotify_update_child_dentry_flags(struct inode *inode); extern struct fsnotify_event_holder *fsnotify_alloc_event_holder(void); extern void fsnotify_destroy_event_holder(struct fsnotify_event_holder *holder); +static inline struct inode *fsnotify_inode(struct fsnotify_obj *obj) +{ + return container_of(obj, struct inode, i_fsnotify); +} + +static inline struct vfsmount *fsnotify_vfsmount(struct fsnotify_obj *obj) +{ + return &(container_of(obj, struct mount, mnt_fsnotify))->mnt; +} + + #endif /* __FS_NOTIFY_FSNOTIFY_H_ */ diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 112f54dceeef..ea6d97f5fc3b 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_inode(obj)); + else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) + conn->mnt = fsnotify_vfsmount(obj); /* * 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 86ea950561a8..4a034e6832ea 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_MAX) - 1) +static inline bool fsnotify_valid_obj_type(unsigned int type) +{ + return (type < FSNOTIFY_OBJ_TYPE_MAX); +} + struct fsnotify_iter_info { struct fsnotify_mark *marks[FSNOTIFY_OBJ_TYPE_MAX]; unsigned int type_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,