From patchwork Fri Sep 21 18:20:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10610839 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 5DD52161F for ; Fri, 21 Sep 2018 18:20:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DC8A2E6C9 for ; Fri, 21 Sep 2018 18:20:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C2812E6D1; Fri, 21 Sep 2018 18:20:43 +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 D1DF02E6D6 for ; Fri, 21 Sep 2018 18:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390912AbeIVAKp (ORCPT ); Fri, 21 Sep 2018 20:10:45 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44508 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390076AbeIVAKp (ORCPT ); Fri, 21 Sep 2018 20:10:45 -0400 Received: by mail-wr1-f65.google.com with SMTP id v16-v6so13718924wro.11 for ; Fri, 21 Sep 2018 11:20:40 -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=EeY7yAhV2Epsxk/1V453uA88dHryurcKB9UOvuj5AAs=; b=FGtDWCw3FWUajeNi4WizJ1AVr7Nj0+nvejLis1/Gg22EZEgpqhMzf9mnMVJNldbYGq IjnUZbdklD1S9mkffz+PPkEd889GielyetuOXsyxlnBhNedT+w7oHFZugbdKG+Pp4GJb BK1qBZsmmV2sgQMyMIw3CujiJTYkEgXjDexHJQENwI0mVHeb8yCq5E3r9k987U0WR0UW AwKEksXseNJP95OPsNvaFhXam/5sUG/q/g6lqfPNtXRkFBCz5fsSIZZRqwH5+BlkigxV aViaQI4VPhxwpTC1cCtUOCor3Rsuv5E26//jP6/BFO/AdsOV1VaooZLirrULZSFg3NRI Wg1g== 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=EeY7yAhV2Epsxk/1V453uA88dHryurcKB9UOvuj5AAs=; b=P8KQCB/0637ugyiZz2kAhwXCh2bb46X/p8RENXvApRD7B91X2ofjLFolDFT2cnrlvk dF8zK0dAFy4V3ADZjxtCGNStpdEYVPGKdUfEsNjxu6xehFPymZNIahmH2TkqbSjeCT8c YFaoZzYBdoY8N7Cii7/9pJ+QjyZPuV41XXUemoTvEvg3MfuR2j4Tc3xqTX8/B5fZWG/i 5zbIUP8IxZhUjnU1HYiNHoYNcTqDeaaZ4UXSN8My5k1l2929cOZpUKFYMzruFj9JrA5H wQZFvtPGLwe/dRBoy2j9fo+6dgSG4p1a5RhcfHViishyUDxBkbq/yl1AwRWWBT7yKtF9 SLSQ== X-Gm-Message-State: ABuFfog4kBFIZ84k2yfG19iwGCw+RgSlC/tSsJYBkM+kGwha60P+6txo 5FB2Mwcoew0bDPvi2ax6Nlaeclyg X-Google-Smtp-Source: ACcGV60hT8/JuFJi6p8rpGYzy+khcC3J33cBuqxJzUJqnv7T3OK/bbtUz0u3aFJEo3/oiYweISgJlQ== X-Received: by 2002:adf:ac4a:: with SMTP id v68-v6mr2735244wrc.165.1537554040093; Fri, 21 Sep 2018 11:20:40 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id v133-v6sm7037787wma.36.2018.09.21.11.20.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 11:20:39 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: nixiaoming@huawei.com, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 1/2] fanotify: store fanotify_init() flags in group's fanotify_data Date: Fri, 21 Sep 2018 21:20:30 +0300 Message-Id: <20180921182031.3184-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921182031.3184-1-amir73il@gmail.com> References: <20180921182031.3184-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 This averts the need to re-generate flags in fanotify_show_fdinfo() and sets the scene for addition of more upcoming flags without growing new members to the fanotify_data struct. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 8 ++++---- fs/notify/fdinfo.c | 24 +----------------------- include/linux/fanotify.h | 4 ++++ include/linux/fsnotify_backend.h | 4 ++-- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 1347c588f778..15719d4aa4b5 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -191,7 +191,7 @@ static int process_access_response(struct fsnotify_group *group, if (fd < 0) return -EINVAL; - if ((response & FAN_AUDIT) && !group->fanotify_data.audit) + if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; event = dequeue_event(group, fd); @@ -701,8 +701,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) struct user_struct *user; struct fanotify_event_info *oevent; - pr_debug("%s: flags=%d event_f_flags=%d\n", - __func__, flags, event_f_flags); + pr_debug("%s: flags=%x event_f_flags=%x\n", + __func__, flags, event_f_flags); if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -746,6 +746,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) } group->fanotify_data.user = user; + group->fanotify_data.flags = flags; atomic_inc(&user->fanotify_listeners); group->memcg = get_mem_cgroup_from_mm(current->mm); @@ -798,7 +799,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) fd = -EPERM; if (!capable(CAP_AUDIT_WRITE)) goto out_destroy_group; - group->fanotify_data.audit = true; } fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 25385e336ac7..348a184bcdda 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -142,31 +142,9 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) void fanotify_show_fdinfo(struct seq_file *m, struct file *f) { struct fsnotify_group *group = f->private_data; - unsigned int flags = 0; - - switch (group->priority) { - case FS_PRIO_0: - flags |= FAN_CLASS_NOTIF; - break; - case FS_PRIO_1: - flags |= FAN_CLASS_CONTENT; - break; - case FS_PRIO_2: - flags |= FAN_CLASS_PRE_CONTENT; - break; - } - - if (group->max_events == UINT_MAX) - flags |= FAN_UNLIMITED_QUEUE; - - if (group->fanotify_data.max_marks == UINT_MAX) - flags |= FAN_UNLIMITED_MARKS; - - if (group->fanotify_data.audit) - flags |= FAN_ENABLE_AUDIT; seq_printf(m, "fanotify flags:%x event-flags:%x\n", - flags, group->fanotify_data.f_flags); + group->fanotify_data.flags, group->fanotify_data.f_flags); show_fdinfo(m, f, fanotify_fdinfo); } diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 096c96f4f16a..9c5ea3bdfaa0 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -6,4 +6,8 @@ /* not valid from userspace, only kernel internal */ #define FAN_MARK_ONDIR 0x00000100 + +#define FAN_GROUP_FLAG(group, flag) \ + ((group)->fanotify_data.flags & (flag)) + #endif /* _LINUX_FANOTIFY_H */ diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 81b88fc9df31..8e91341cbd8a 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -189,10 +189,10 @@ struct fsnotify_group { /* allows a group to block waiting for a userspace response */ struct list_head access_list; wait_queue_head_t access_waitq; - int f_flags; + int flags; /* flags from fanotify_init() */ + int f_flags; /* event_f_flags from fanotify_init() */ unsigned int max_marks; struct user_struct *user; - bool audit; } fanotify_data; #endif /* CONFIG_FANOTIFY */ };