From patchwork Sat Jun 23 14:54:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10483677 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 F329F601C8 for ; Sat, 23 Jun 2018 14:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D01E52857F for ; Sat, 23 Jun 2018 14:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C51EB28599; Sat, 23 Jun 2018 14:53:32 +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 56B562857F for ; Sat, 23 Jun 2018 14:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751638AbeFWOxa (ORCPT ); Sat, 23 Jun 2018 10:53:30 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:39335 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751506AbeFWOx0 (ORCPT ); Sat, 23 Jun 2018 10:53:26 -0400 Received: by mail-wr0-f193.google.com with SMTP id b8-v6so3920295wro.6 for ; Sat, 23 Jun 2018 07:53:26 -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=nXAsQYe60YPsEZKKW30i6sGl8V2XDeQD4LZdZqcZZ4Y=; b=KAtGHRuIR2GfgZ4rp/t897eCI2sH5jYdRE3jmhSMw/Pxrq3b8YyPjeGHmHIjOGZnFp UClpj3Zbe282ClrFbzvqtgszFSs4NHCEmAhQjaSymfNIB60Iga2llu2co4CvSisxxx7A Z9UFTmLjcTnkdZ2Fh23qTKB8WjvGqASyIGC/A/OREwfEXKdp2tx3e6/SywVYArHnlbFk cwZt3AnxoMEixs5GHF0uZv8xprvLdHHIWB0kDV7s+XHrqoQSYShy7FXaNZrnB2Uex0HY YI6z5JlbAASE35pb5qFpD2zmcVz+v89K43sREer9FL1uo1CTUgiFN4wd+7EhfU0af4z1 21sQ== 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=nXAsQYe60YPsEZKKW30i6sGl8V2XDeQD4LZdZqcZZ4Y=; b=S7dfiH1yTyMnGvvwNol24cQtjwaAVSiPgxHLZw9Nqxzmp+8lLaUdv85/rRt0Vs86WA DlkRqwkfuLRTY3r49uUBddgHmg7ty1NrGYgTXd/9Ud4YaRVYWdVA4q1MItadOrbLSAJ8 i64AdN2P6MC1c1WFJSA7NXrQ5Z7iPzEfkB9alE+cWH0errxo6f4YJXf23ZM+z6lo0XEX Rzh4A4LBh9dWRORvSyjVu3vfWoW7G9uu1xEVCUCKRhmI12qjxE0I0H+kd//IVnxFjeA4 3CzbGZS3l8ggKAWPl2/1RIRj2jsgc0AV3LjtINay9aL4hTU0/yVQIJO9bZwvbB0CGGUp r5lQ== X-Gm-Message-State: APt69E0FdzjmNHz8dDMLjRKs8TUMaB0utMbXoWr4VbmulTGF0YW5W5YM WW9rGjZQWxVfnEXQXOFWgPw= X-Google-Smtp-Source: ADUXVKJqmC5ZimUhSoNYOe9B4rnwDqvO2R5b8d44EWtAf6XRVUp4brmSf1S3TrLzHHUnNiJSJGEHVA== X-Received: by 2002:a5d:478d:: with SMTP id w13-v6mr4572722wrq.188.1529765605461; Sat, 23 Jun 2018 07:53:25 -0700 (PDT) Received: from localhost.localdomain ([5.102.238.247]) by smtp.gmail.com with ESMTPSA id w3-v6sm9478064wrr.88.2018.06.23.07.53.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 23 Jun 2018 07:53:24 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v4 5/5] fanotify: factor out helpers to add/remove mark Date: Sat, 23 Jun 2018 17:54:51 +0300 Message-Id: <1529765691-25170-6-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529765691-25170-1-git-send-email-amir73il@gmail.com> References: <1529765691-25170-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 Factor out helpers fanotify_add_mark() and fanotify_remove_mark() to reduce duplicated code. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 86 +++++++++++++------------------------- 1 file changed, 29 insertions(+), 57 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 3899ad177651..d736a833fe39 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -524,17 +524,16 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, return mask & oldmask; } -static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, - struct vfsmount *mnt, __u32 mask, - unsigned int flags) +static int fanotify_remove_mark(struct fsnotify_group *group, + fsnotify_connp_t *connp, __u32 mask, + unsigned int flags) { struct fsnotify_mark *fsn_mark = NULL; __u32 removed; int destroy_mark; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&real_mount(mnt)->mnt_fsnotify_marks, - group); + fsn_mark = fsnotify_find_mark(connp, group); if (!fsn_mark) { mutex_unlock(&group->mark_mutex); return -ENOENT; @@ -550,39 +549,25 @@ static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, if (destroy_mark) fsnotify_free_mark(fsn_mark); + /* matches the fsnotify_find_mark() */ fsnotify_put_mark(fsn_mark); return 0; } +static int fanotify_remove_vfsmount_mark(struct fsnotify_group *group, + struct vfsmount *mnt, __u32 mask, + unsigned int flags) +{ + return fanotify_remove_mark(group, &real_mount(mnt)->mnt_fsnotify_marks, + mask, flags); +} + static int fanotify_remove_inode_mark(struct fsnotify_group *group, struct inode *inode, __u32 mask, unsigned int flags) { - struct fsnotify_mark *fsn_mark = NULL; - __u32 removed; - int destroy_mark; - - mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group); - if (!fsn_mark) { - mutex_unlock(&group->mark_mutex); - return -ENOENT; - } - - removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, - &destroy_mark); - if (removed & fsnotify_conn_mask(fsn_mark->connector)) - fsnotify_recalc_mask(fsn_mark->connector); - if (destroy_mark) - fsnotify_detach_mark(fsn_mark); - mutex_unlock(&group->mark_mutex); - if (destroy_mark) - fsnotify_free_mark(fsn_mark); - - /* matches the fsnotify_find_mark() */ - fsnotify_put_mark(fsn_mark); - - return 0; + return fanotify_remove_mark(group, &inode->i_fsnotify_marks, mask, + flags); } static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, @@ -639,19 +624,17 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, } -static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, - struct vfsmount *mnt, __u32 mask, - unsigned int flags) +static int fanotify_add_mark(struct fsnotify_group *group, + fsnotify_connp_t *connp, unsigned int type, + __u32 mask, unsigned int flags) { - fsnotify_connp_t *connp = &real_mount(mnt)->mnt_fsnotify_marks; struct fsnotify_mark *fsn_mark; __u32 added; mutex_lock(&group->mark_mutex); fsn_mark = fsnotify_find_mark(connp, group); if (!fsn_mark) { - fsn_mark = fanotify_add_new_mark(group, connp, - FSNOTIFY_OBJ_TYPE_VFSMOUNT); + fsn_mark = fanotify_add_new_mark(group, connp, type); if (IS_ERR(fsn_mark)) { mutex_unlock(&group->mark_mutex); return PTR_ERR(fsn_mark); @@ -666,14 +649,18 @@ static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, return 0; } +static int fanotify_add_vfsmount_mark(struct fsnotify_group *group, + struct vfsmount *mnt, __u32 mask, + unsigned int flags) +{ + return fanotify_add_mark(group, &real_mount(mnt)->mnt_fsnotify_marks, + FSNOTIFY_OBJ_TYPE_VFSMOUNT, mask, flags); +} + static int fanotify_add_inode_mark(struct fsnotify_group *group, struct inode *inode, __u32 mask, unsigned int flags) { - fsnotify_connp_t *connp = &inode->i_fsnotify_marks; - struct fsnotify_mark *fsn_mark; - __u32 added; - pr_debug("%s: group=%p inode=%p\n", __func__, group, inode); /* @@ -686,23 +673,8 @@ static int fanotify_add_inode_mark(struct fsnotify_group *group, (atomic_read(&inode->i_writecount) > 0)) return 0; - mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(connp, group); - if (!fsn_mark) { - fsn_mark = fanotify_add_new_mark(group, connp, - FSNOTIFY_OBJ_TYPE_INODE); - if (IS_ERR(fsn_mark)) { - mutex_unlock(&group->mark_mutex); - return PTR_ERR(fsn_mark); - } - } - added = fanotify_mark_add_to_mask(fsn_mark, mask, flags); - if (added & ~fsnotify_conn_mask(fsn_mark->connector)) - fsnotify_recalc_mask(fsn_mark->connector); - mutex_unlock(&group->mark_mutex); - - fsnotify_put_mark(fsn_mark); - return 0; + return fanotify_add_mark(group, &inode->i_fsnotify_marks, + FSNOTIFY_OBJ_TYPE_INODE, mask, flags); } /* fanotify syscalls */