From patchwork Tue Sep 18 15:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10604515 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 34340112B for ; Tue, 18 Sep 2018 15:44:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20EC82B5F1 for ; Tue, 18 Sep 2018 15:44:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 130F42B68C; Tue, 18 Sep 2018 15:44:50 +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 9DB3F2B5F1 for ; Tue, 18 Sep 2018 15:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729726AbeIRVR5 (ORCPT ); Tue, 18 Sep 2018 17:17:57 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38423 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729447AbeIRVR4 (ORCPT ); Tue, 18 Sep 2018 17:17:56 -0400 Received: by mail-wm1-f67.google.com with SMTP id t25-v6so3373652wmi.3 for ; Tue, 18 Sep 2018 08:44:46 -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; bh=AhMawrBXi5LalNbkSOAR+OOoe/D4c/fvqFWxcJnwLp0=; b=Tffu7mxUVClz2mbElHZhsnm0cTZA+YGMG05rM54wB9norgHiTwFmD7MBEXOJ3uFVS6 xX/qQN0EXgFn/a+a/HzznbMVXe4ciYwz+WB/n11NpKmVjzPu54AfblzHlqkY3dmJCwT/ AwUUcjGC+ek2bzEMYu8WLHGSf5dODg60fcYV/rpRLVGHUmjB5j9w4kwYClKoE51zVsja zQao0ppm+f5C32KpjjY1Hhf75VgZTxY67440nlT/rG6lDOajTjaMNYUOMtGqr6+9MS3z A3VHdH0FKHvWc0eMV1u7cE8qzcrclenZ1Wvmivt4WLTffm78m/LhagX7DTwut8KUYQUA xbdA== 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; bh=AhMawrBXi5LalNbkSOAR+OOoe/D4c/fvqFWxcJnwLp0=; b=TSCezZDmMJ8Qrnuk/eBjnonvvGfEXe9gRhobLsg8msK8NCmlb1YRs3ppnh541Mwe2U FDFLSUQf2h5F38FHuQg7LEDbOudGaV2ekJgvPyyCppe6kJVUed2Yd42GPJgOXiuhVhds fkTIIxeOAWrwN7zLKpJpeQmWI3HjaislLNAMuKV2ARPu38sDtvVyLOs696NZIo0SP8gY nTUvf8KnRKm5yGDkXaUzbLqoyHu5NcM08dzUkSHqedssPNXEnzWXGr1u2+OpQxRtS7DQ 6UlNPkUPLTLnXupHGhfXl/WOM69Ch7V5wbdqMkCHCt1Wzjdu7QkO34Gkgl8yxKmydFMY Z37A== X-Gm-Message-State: APzg51Dsaj5hjJnfCaP910kF37Fb2a3bwjNNy/smIFx18cI20FsmMf0I 4KsQZvc5/6EClVHMP9qowRU= X-Google-Smtp-Source: ANB0VdZz+MLWFmZgm7xCK7htYqJkDd8P9FrSWh7xX/rwcSldhn6LxDJGIIBadW5FVKoeyCHKi5UURA== X-Received: by 2002:a1c:448b:: with SMTP id r133-v6mr15578754wma.128.1537285485400; Tue, 18 Sep 2018 08:44:45 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id y10-v6sm17051908wrl.87.2018.09.18.08.44.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 08:44:44 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: nixiaoming@huawei.com, linux-fsdevel@vger.kernel.org Subject: [PATCH] fanotify: store fanotify_init() flags in group's fanotify_data Date: Tue, 18 Sep 2018 18:44:34 +0300 Message-Id: <20180918154434.10299-1-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 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 --- Jan, Please consider this small "cleanup" patch for next. It's part of my fanotify_dentry series, so wasn't going to send it out yet, but seems like other developers can find it useful [1] in the mean while. Thanks, Amir. [1] https://lkml.org/lkml/2018/9/18/942 fs/notify/fanotify/fanotify_user.c | 9 +++++---- fs/notify/fdinfo.c | 24 +----------------------- include/linux/fsnotify_backend.h | 4 ++-- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 1347c588f778..0562738a4c51 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -191,7 +191,8 @@ 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) && + !(group->fanotify_data.flags & FAN_ENABLE_AUDIT)) return -EINVAL; event = dequeue_event(group, fd); @@ -701,8 +702,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; @@ -798,13 +799,13 @@ 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); if (fd < 0) goto out_destroy_group; + group->fanotify_data.flags = flags; return fd; out_destroy_group: 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/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 */ };