From patchwork Wed Jul 22 12:58:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B77E413A4 for ; Wed, 22 Jul 2020 12:59:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BDCC22C9D for ; Wed, 22 Jul 2020 12:59:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dE+a14kk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732352AbgGVM7F (ORCPT ); Wed, 22 Jul 2020 08:59:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbgGVM7F (ORCPT ); Wed, 22 Jul 2020 08:59:05 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C80C0619DC for ; Wed, 22 Jul 2020 05:59:04 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id a6so4337329wmm.0 for ; Wed, 22 Jul 2020 05:59:04 -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=h7rlIMvMfReNuqNoJRnArogxvKRNNgJ+jKsezYqIUo8=; b=dE+a14kkCuX52hMUMTAjrqUtAz54EAIdOqDfiVC28zGJgvlg64XtIDvCEa4Tr2kvr0 kDG5wj6yYuERArKYXG4gmmJ5agqv+qrrX9vqPlHdZ4SVJsVCFpU84jDppFXqaxItHIdx rY/nXMpudbeRwcgjRZUYaRb9pMvuJ8JmWb5IgZegxtcOToBc8g2lN6aAyuuLZf1GSrMe 91wG5QcSPDNlD0zK74U1rHracn8tIUeaDrnT77RPEOsohy6v8xcoy+jDqvZKhWOFMFZC NoP1+IphknfnD7bmLvmpkWrq7AKXyz86G7WsaJGYChnxWeGEAHmO6Tyw+pvFkx4+Gi/W vLRA== 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=h7rlIMvMfReNuqNoJRnArogxvKRNNgJ+jKsezYqIUo8=; b=Nle2jKz74bkysGtiKyWnDIWc4RrqF2Mo1PZxklpTTkU/sWiZNAodpSCxS4svpMRG4J eQJxgobqDNGqAdLLlIkdZ1Cj/GKtXNtAV+ovd8IG5xB96+VV/iZ1gjEcnfPW0JOaj9mY RTkVBg9vrRaAwwYtms3H5QKz0B6lszb2HzqJr/bpEzCfRa7fo+Y/5Js4C8JnSlXSM0RW KDBOPNbt9+vyC/dJ2qsuRrUmP1vubv7vNUWhkNVbKkPNjWLVgi59aV+LtJv/JsQOMF7A 4+TD1/Zw1DUQ0J71ulTFmcWScubakdpldIXiGp86fvs+WJKeZcZn6UaATl/MRieRoAtk vovg== X-Gm-Message-State: AOAM533DITfnCang1hEsGvmHJWuJKqwJ49tbT78GvyR3WH/z2gaucO/3 0B1mroQ6ozWo2njTRe20h6I= X-Google-Smtp-Source: ABdhPJx8KN6idgyOFySHA2uA6TN51CuSDU8fXGCkVwqa8cfjTamgfFP4Aya6PzfJJIzKr++io7pQKw== X-Received: by 2002:a1c:2bc1:: with SMTP id r184mr9036827wmr.133.1595422743486; Wed, 22 Jul 2020 05:59:03 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:02 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 1/9] fanotify: fix reporting event to sb/mount marks Date: Wed, 22 Jul 2020 15:58:41 +0300 Message-Id: <20200722125849.17418-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When reporting event with parent/name info, we should not skip sb/mount marks mask if event has FAN_EVENT_ON_CHILD in the mask. This check is a leftover from the time when the event on child was reported in a separate callback than the event on parent and we did not want to get duplicate events for sb/mount mark. Fixes: eca4784cbb18 ("fsnotify: send event to parent and child with single callback") Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index a24f08a9c50f..36ea0cd6387e 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -265,13 +265,11 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, continue; /* - * If the event is for a child and this mark doesn't care about - * events on a child, don't send it! - * The special object type "child" always cares about events on - * a child, because it refers to the child inode itself. + * If the event is for a child and this mark is on a parent not + * watching children, don't send it! */ if (event_mask & FS_EVENT_ON_CHILD && - type != FSNOTIFY_OBJ_TYPE_CHILD && + type == FSNOTIFY_OBJ_TYPE_INODE && !(mark->mask & FS_EVENT_ON_CHILD)) continue; From patchwork Wed Jul 22 12:58:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A08A413B1 for ; Wed, 22 Jul 2020 12:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8730B20787 for ; Wed, 22 Jul 2020 12:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EJTv9cE1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732359AbgGVM7J (ORCPT ); Wed, 22 Jul 2020 08:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbgGVM7G (ORCPT ); Wed, 22 Jul 2020 08:59:06 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5AEC0619DC for ; Wed, 22 Jul 2020 05:59:06 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id a6so4337371wmm.0 for ; Wed, 22 Jul 2020 05:59:06 -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=LwjKIox4FCFrccXbofKj5hB5esw+QCHsR17VPIIhsQE=; b=EJTv9cE10qRaQEAShmWfDWhRnN+QIo+pREmW0YWvj6nTmAHwiivulnIY8DzkmirgM+ nHCUs/03s/6rHoAfrQgQOtZ56L3BHHaKjrbTWOzKXkM5uKzYyMGylPP8DVy4Xw+p3Al8 mRba1eTpRODh1eiVdkVNzCL8VB1qfcCWvCT6zf3eMxaDroU3YFIZDYyBHia+1MxH9Ht2 JLOcHQD0oJNmsjmSl+sC6XgOlrxJdZZ3xWAZz6ml9UDYarBxPtshnaHtNuspHprcw3xI WW38OpM8jg+fuGVAdom5W0+4glqZhNlDWuaXXYIDXLt6ZJK9TcZRsWji1FhaDPKofdpB 6Pqw== 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=LwjKIox4FCFrccXbofKj5hB5esw+QCHsR17VPIIhsQE=; b=ceUiMUQkkqZKvpatiGEYnU298hx1bF0U2K4K9mvsS4VQYR+YSvUu0sZJoqPgZAlkZn 1LezyQyKbMmGqUixIVaAPNhRpSaVrD5QdaDZYOnbyzbn5fJNQ9dOXWA2EhsxX/HkRn8K U8CQrg4QEQ3E5sGuJjGPFhuIgIIrKbODWuGUQR5OZYF8GWsxaOIZUNv3M51zHb2rvIUq ygN1Fr0B89N5b0Zwu1hfa+7+jO1xIPLqN8lilM83UB0BjxFnFed0soGzIi36dRzmChtO wEWrsHiaGHGWPaVvFOPI8Lkqu72PblX6t7ndLI0Dve5zyqhA+V0R94qfNCHQkzRtmM2a dJCQ== X-Gm-Message-State: AOAM531+x3NZATRibNRGFaownCVQEFxeIFUFYeAqhubFz10HDS12BPzq NwpJtmJCH+6v+cXajkB5+YI= X-Google-Smtp-Source: ABdhPJzt8AJs0NSj+Uc9/jzL5O4ISIhf5JtAJQYlj8TLL7sHAS14hgSkm88HSTMzrBVGBVVRfz9alQ== X-Received: by 2002:a7b:c747:: with SMTP id w7mr1736600wmk.136.1595422744978; Wed, 22 Jul 2020 05:59:04 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:04 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 2/9] inotify: do not set FS_EVENT_ON_CHILD in non-dir mark mask Date: Wed, 22 Jul 2020 15:58:42 +0300 Message-Id: <20200722125849.17418-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since commit ecf13b5f8fd6 ("fsnotify: send event with parent/name info to sb/mount/non-dir marks") the flag FS_EVENT_ON_CHILD has a meaning in mask of a mark on a non-dir inode. It means that group is interested in the name of the file with events. Since inotify is only intereseted in names of children of a watching parent, do not sete FS_EVENT_ON_CHILD flag for marks on non-dir. Signed-off-by: Amir Goldstein --- fs/notify/inotify/inotify_user.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 5385d5817dd9..186722ba3894 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -75,15 +75,17 @@ struct ctl_table inotify_table[] = { }; #endif /* CONFIG_SYSCTL */ -static inline __u32 inotify_arg_to_mask(u32 arg) +static inline __u32 inotify_arg_to_mask(struct inode *inode, u32 arg) { __u32 mask; /* - * everything should accept their own ignored, cares about children, - * and should receive events when the inode is unmounted + * Everything should accept their own ignored and should receive events + * when the inode is unmounted. All directories care about children. */ - mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_UNMOUNT); + mask = (FS_IN_IGNORED | FS_UNMOUNT); + if (S_ISDIR(inode->i_mode)) + mask |= FS_EVENT_ON_CHILD; /* mask off the flags used to open the fd */ mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK)); @@ -512,7 +514,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, int create = (arg & IN_MASK_CREATE); int ret; - mask = inotify_arg_to_mask(arg); + mask = inotify_arg_to_mask(inode, arg); fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group); if (!fsn_mark) @@ -565,7 +567,7 @@ static int inotify_new_watch(struct fsnotify_group *group, struct idr *idr = &group->inotify_data.idr; spinlock_t *idr_lock = &group->inotify_data.idr_lock; - mask = inotify_arg_to_mask(arg); + mask = inotify_arg_to_mask(inode, arg); tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL); if (unlikely(!tmp_i_mark)) From patchwork Wed Jul 22 12:58:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DCF413A4 for ; Wed, 22 Jul 2020 12:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55DC220729 for ; Wed, 22 Jul 2020 12:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WwU0GeoF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732357AbgGVM7I (ORCPT ); Wed, 22 Jul 2020 08:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732353AbgGVM7I (ORCPT ); Wed, 22 Jul 2020 08:59:08 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8982AC0619DE for ; Wed, 22 Jul 2020 05:59:07 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id p14so1474123wmg.1 for ; Wed, 22 Jul 2020 05:59:07 -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=uOcSKEZdq5c4M49zjYhdnvMf+g+7K75mT6pfhu0KNtI=; b=WwU0GeoFS17Z8YniS55vQFieQ55hulHu0zJjHx8zYsXvqIAfdbquL/m+CTkGh2wilr qTscUZVn5Vy0UAc65IPEQZvCg9avpilsmYKHdHVRnZzYY0L7zs/VsLlOlRK3+0b0MwtR 5zZIMPUUI/O6gtqNymtT0EY1iKDnnuJi0KTKtC7ZP6wc9Y3LkbJxdfr9d0ENW7YjQR3g G+09hhzpatTvqiAOWriIDeKFBOLTnSs205EEwpW6RCjSsFaJKXq8rvaZ4fiSzZOYmK4f xYgh/TBHQFZefeCjOkp6vBTfQRRTamSVMyT2Pq4RvVDppKh+XMOBY4HUDTu8t4Vslg/R Hs1w== 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=uOcSKEZdq5c4M49zjYhdnvMf+g+7K75mT6pfhu0KNtI=; b=aWDmaRghF5cLDCaCpjXNmHkFUta+DchZWduuTLhNvYcKvkrcjOVPxfXiBzSkAcLwqX h6Fq9ygK77QtsXxBFg4ods0YbQYcjwoO6BU9ccJtedFnNSA8yd4r0CIrVwh2e+pysw1Z h3wNwh7PBuMqRdopMeCnYZC7fZjk4M4B/MpnDvHQd0s5S+upmB7E+S4UR4K4ku0JjAyx bG3X1rKL9Qw+jNn28nzIHPldJnVoG4aPtAU/c3pVTiJE2T9zo13G5gl+/fD4X8WNRlCU ROVMut7HKD0qe2Whfm9L251sv/FLnrOtmwAY8H/43PsuojQv6e/smUd8lhB46lW+bDEo Z+6w== X-Gm-Message-State: AOAM530kSfHOPZPLGsOLPwbFzvoRDVQLeFXGP2uBqWzrsxm7EjcsMO1X sPQEwSQtojCXDBSAnDhaOs2QkdOz X-Google-Smtp-Source: ABdhPJxlfxni5l7PBT8l1RAIHHQwdAmZzb5Z+Xp6jHZIqF+BVeDJ9rksKdUxKM8TOae0PpD4oQhz5A== X-Received: by 2002:a7b:c0da:: with SMTP id s26mr7931092wmh.96.1595422746344; Wed, 22 Jul 2020 05:59:06 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:05 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 3/9] audit: do not set FS_EVENT_ON_CHILD in audit marks mask Date: Wed, 22 Jul 2020 15:58:43 +0300 Message-Id: <20200722125849.17418-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The audit groups marks mask does not contain any events possible on child,so setting the flag FS_EVENT_ON_CHILD in the mask is counter productive. It may lead to the undesired outcome of setting the dentry flag DCACHE_FSNOTIFY_PARENT_WATCHED on a directory inode even though it is not watching children, because the audit mark contribute the flag FS_EVENT_ON_CHILD to the inode's fsnotify_mask and another mark could be contributing an event that is possible on child to the inode's mask. Signed-off-by: Amir Goldstein --- kernel/audit_fsnotify.c | 2 +- kernel/audit_watch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index 30ca239285a3..bd3a6b79316a 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -36,7 +36,7 @@ static struct fsnotify_group *audit_fsnotify_group; /* fsnotify events we care about. */ #define AUDIT_FS_EVENTS (FS_MOVE | FS_CREATE | FS_DELETE | FS_DELETE_SELF |\ - FS_MOVE_SELF | FS_EVENT_ON_CHILD) + FS_MOVE_SELF) static void audit_fsnotify_mark_free(struct audit_fsnotify_mark *audit_mark) { diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index 61fd601f1edf..e23d54bcc587 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -53,7 +53,7 @@ static struct fsnotify_group *audit_watch_group; /* fsnotify events we care about. */ #define AUDIT_FS_WATCH (FS_MOVE | FS_CREATE | FS_DELETE | FS_DELETE_SELF |\ - FS_MOVE_SELF | FS_EVENT_ON_CHILD | FS_UNMOUNT) + FS_MOVE_SELF | FS_UNMOUNT) static void audit_free_parent(struct audit_parent *parent) { From patchwork Wed Jul 22 12:58:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4F7213A4 for ; Wed, 22 Jul 2020 12:59:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D1F220729 for ; Wed, 22 Jul 2020 12:59:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LVx/0Bhu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732382AbgGVM7J (ORCPT ); Wed, 22 Jul 2020 08:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbgGVM7J (ORCPT ); Wed, 22 Jul 2020 08:59:09 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D887AC0619DC for ; Wed, 22 Jul 2020 05:59:08 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id 17so1922460wmo.1 for ; Wed, 22 Jul 2020 05:59:08 -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=mq4lMGMMRabdtLMbjK6o4L3vb3t6wnKYpHTiwhaTctk=; b=LVx/0Bhu7coOa1v5ZMIyZkn3IjHhWCD9xitZW14b5Jke3AzjcN5a6VNMRmshv+EH8J tMvAXshJQChlBMT1Neq4gKGwas+YV3KluuhxRg0sFgvF4hMlM88hpaGKOol8h4vu4BJk fFM3DEseQ+un/Y/lzUtf6ZJOdZevUHy8j2NEd4z0wukvsF4tVBo9j3AUN7OrrpJzdzw+ 7oSSBNTuphYh0fqp1+FDkYd6R+707vVpI9+2QOiV7JQcbssE96ZiRhNK5JXmu38SOaV3 Hz7uMTlLjlDxd+TwPPoYc/uBoaQ2PYV5bvvcqX20XVvEgPfq2lc8KOlYjPBt5XLZ2oQV fNHA== 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=mq4lMGMMRabdtLMbjK6o4L3vb3t6wnKYpHTiwhaTctk=; b=PqIvoNPU1yC3kkGRL6l618kJM8+qtMu7ypkKKOsKPoNtYXFtqEeFxJghWF56R2BAMN /w0lF6jDagJFq0vqAOcFwt+SRSolu8/K825djTDxKagkXPeQ/UJpyupGMH8bVOtT9cCj S7dtfTXNJyU/Pb0RkGZcWpbfQufN1MOZ2jACJVIL0Arpr7iEzm6qnPc5VSLUbjjQ9KI8 6qqNFeXT7z6P3yRD/NRWN8pzI3nwb5P29VPNz9nEonqq0WX7PSU5j4Eu+a9FmLCH36sn maNqGRo9xM8ATjo6Z4Mti+s1jT6Adw/0ZzRxmhZNoLLzM4p+F5Coaxs6i3A1X5EiQGtl 6chw== X-Gm-Message-State: AOAM530ddzwx9cOXNQqatydtSWwwHTxbT4XwYCSK78d6VdLTdsrOy/oA AGk4UyFa1OYfK78QB3fYGfc= X-Google-Smtp-Source: ABdhPJxmUsElyoKjdxjszpYO9J0AsB8J5TPz4gPENxsenHHOHmDqZtFFepMc6nHqLxCdzOC9JscqWg== X-Received: by 2002:a7b:c936:: with SMTP id h22mr8094290wml.114.1595422747601; Wed, 22 Jul 2020 05:59:07 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:07 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 4/9] fsnotify: create helper fsnotify_inode() Date: Wed, 22 Jul 2020 15:58:44 +0300 Message-Id: <20200722125849.17418-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Simple helper to consolidate biolerplate code. Signed-off-by: Amir Goldstein --- fs/kernfs/file.c | 6 ++---- fs/notify/fsnotify.c | 2 +- include/linux/fsnotify.h | 26 +++++++++++--------------- kernel/trace/trace.c | 3 +-- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 5b1468bc509e..1d185bffc52f 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -910,10 +910,8 @@ static void kernfs_notify_workfn(struct work_struct *work) kernfs_put(parent); } - if (!p_inode) { - fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE, - NULL, 0); - } + if (!p_inode) + fsnotify_inode(inode, FS_MODIFY); iput(inode); } diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index efa5c1c4908a..277af3d5efce 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -74,7 +74,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb) iput(iput_inode); /* for each watch, send FS_UNMOUNT and then remove it */ - fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_inode(inode, FS_UNMOUNT); fsnotify_inode_delete(inode); diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index fe4f2bc5b4c2..01b71ad91339 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -38,6 +38,14 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0); } +static inline void fsnotify_inode(struct inode *inode, __u32 mask) +{ + if (S_ISDIR(inode->i_mode)) + mask |= FS_ISDIR; + + fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); +} + /* Notify this dentry's parent about a child's events. */ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type) @@ -111,12 +119,7 @@ static inline int fsnotify_perm(struct file *file, int mask) */ static inline void fsnotify_link_count(struct inode *inode) { - __u32 mask = FS_ATTRIB; - - if (S_ISDIR(inode->i_mode)) - mask |= FS_ISDIR; - - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_inode(inode, FS_ATTRIB); } /* @@ -131,7 +134,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, u32 fs_cookie = fsnotify_get_cookie(); __u32 old_dir_mask = FS_MOVED_FROM; __u32 new_dir_mask = FS_MOVED_TO; - __u32 mask = FS_MOVE_SELF; const struct qstr *new_name = &moved->d_name; if (old_dir == new_dir) @@ -140,7 +142,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, if (isdir) { old_dir_mask |= FS_ISDIR; new_dir_mask |= FS_ISDIR; - mask |= FS_ISDIR; } fsnotify_name(old_dir, old_dir_mask, source, old_name, fs_cookie); @@ -149,7 +150,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, if (target) fsnotify_link_count(target); - fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_inode(source, FS_MOVE_SELF); audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); } @@ -174,12 +175,7 @@ static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) */ static inline void fsnotify_inoderemove(struct inode *inode) { - __u32 mask = FS_DELETE_SELF; - - if (S_ISDIR(inode->i_mode)) - mask |= FS_ISDIR; - - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_inode(inode, FS_DELETE_SELF); __fsnotify_inode_delete(inode); } diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index bb62269724d5..0c655c039506 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1543,8 +1543,7 @@ static void latency_fsnotify_workfn(struct work_struct *work) { struct trace_array *tr = container_of(work, struct trace_array, fsnotify_work); - fsnotify(tr->d_max_latency->d_inode, FS_MODIFY, - tr->d_max_latency->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify_inode(tr->d_max_latency->d_inode, FS_MODIFY); } static void latency_fsnotify_workfn_irq(struct irq_work *iwork) From patchwork Wed Jul 22 12:58:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC24A13B1 for ; Wed, 22 Jul 2020 12:59:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D4A20657 for ; Wed, 22 Jul 2020 12:59:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rt/gYXBI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732394AbgGVM7N (ORCPT ); Wed, 22 Jul 2020 08:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbgGVM7K (ORCPT ); Wed, 22 Jul 2020 08:59:10 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF76C0619DC for ; Wed, 22 Jul 2020 05:59:10 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id s10so1794038wrw.12 for ; Wed, 22 Jul 2020 05:59:10 -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=2wYA7mBMODKNUAV9pBdhQQeD4kLfNGRYjkDwVOQ8Szk=; b=rt/gYXBIk9/WuQevRfq2WyEg62A1Zr991uzj1t5kaUXVuF5sRomFPEm7fkxjo0HIn3 jP2Kgy0BLWtdoZvM3ZA4MbXu8wJuIIyU/8C+Og2dwQhyaITW5HPWkNJI5A3h5TxnvMa8 FcwNrVHEAn5oOBPX9iLkEmz9MOfZsYDSDe46RUk//7+fBAJgP8Yi/jW6Kh7u0VHndrxL g4e9zO49ZDCHcELzRKKObltF9Y1eKFaNVee2DSIETpv+Vu08sxE4Shfca3lpAbBbS6K9 Ju3ewSiFhcXt2r/fbLik4nSHT+ZzXxqn6e70uYKAYcvYDKOH39FboGBU1c4H8WjsQFio F5xA== 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=2wYA7mBMODKNUAV9pBdhQQeD4kLfNGRYjkDwVOQ8Szk=; b=JNiklPGM+Yr407QYdvQWMJV5JUBzDOyE6IkPJpTILPdH6/BnDS5NAJsErsZwwVuqbE AA0TbrXRgd1O99GjmFgZbtUGPxGR3dCxOZCBZMuuyp8yIRBlhoh1oEQ7LiKNmDtJY7WA jbeYiC2fxfuVEz8ml/ryU69cljkTjZCf/jAQKBOp+7RMVysYnQqOaOQwOMtEZA/A/lfv PBHF+Tcz9FJASCj+LCtyYDI8tqepBU3Qgn4ZETH/kFaKhAyMjGPl0VGY0blyrVu81cJr +P3+hD6FM+oD2+foWirgW3fAJEqTPyozh3fPmotjQlB7CSsy7FsnUlu2X9V5jh0lsnLC K5EQ== X-Gm-Message-State: AOAM531thzX16/aMBPlRit6yKipLUeu7liWpjcLL5I9d/3nKgKHZkPY4 SYl92tVO+fDa1DF0Npk0xms= X-Google-Smtp-Source: ABdhPJxlxVymyMVaRm8XZw23Bx6d8HKu2NrmYngw4IEdVLi9F1CdE7p3MJbyCE1TYACHXtR7lGGTKw== X-Received: by 2002:adf:ec90:: with SMTP id z16mr31011034wrn.52.1595422748954; Wed, 22 Jul 2020 05:59:08 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:08 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 5/9] fsnotify: simplify dir argument to handle_event() Date: Wed, 22 Jul 2020 15:58:45 +0300 Message-Id: <20200722125849.17418-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The meaning of dir argument could be simplified a lot to just the base of file_name it we let the only backends that care about it (fanotify and dnotify) cope with the case of NULL file_name themselves, which is easy. This will make dir argument meaning generic enough so we can use the same argument for fsnotify() without causing confusion. Fixes: e2c9d9039c3f ("fsnotify: pass dir argument to handle_event() callback") Signed-off-by: Amir Goldstein --- fs/notify/dnotify/dnotify.c | 2 +- fs/notify/fanotify/fanotify.c | 7 ++++--- fs/notify/fsnotify.c | 2 +- include/linux/fsnotify_backend.h | 4 +--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 305e5559560a..ca78d3f78da8 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -112,7 +112,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, struct fsnotify_mark *child_mark = fsnotify_iter_child_mark(iter_info); /* not a dir, dnotify doesn't care */ - if (!dir) + if (!dir && !(mask & FS_ISDIR)) return 0; if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info))) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 36ea0cd6387e..03e3dce2a97c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -245,7 +245,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, return 0; } else if (!(fid_mode & FAN_REPORT_FID)) { /* Do we have a directory inode to report? */ - if (!dir) + if (!dir && !(event_mask & FS_ISDIR)) return 0; } @@ -525,12 +525,13 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, struct fanotify_event *event = NULL; gfp_t gfp = GFP_KERNEL_ACCOUNT; struct inode *id = fanotify_fid_inode(mask, data, data_type, dir); + struct inode *dirid = fanotify_dfid_inode(mask, data, data_type, dir); const struct path *path = fsnotify_data_path(data, data_type); unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); struct inode *child = NULL; bool name_event = false; - if ((fid_mode & FAN_REPORT_DIR_FID) && dir) { + if ((fid_mode & FAN_REPORT_DIR_FID) && dirid) { /* * With both flags FAN_REPORT_DIR_FID and FAN_REPORT_FID, we * report the child fid for events reported on a non-dir child @@ -540,7 +541,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, (mask & FAN_EVENT_ON_CHILD) && !(mask & FAN_ONDIR)) child = id; - id = fanotify_dfid_inode(mask, data, data_type, dir); + id = dirid; /* * We record file name only in a group with FAN_REPORT_NAME diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 277af3d5efce..834775f61f6b 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -365,7 +365,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, const struct path *path = fsnotify_data_path(data, data_type); struct fsnotify_iter_info iter_info = {}; struct super_block *sb = to_tell->i_sb; - struct inode *dir = S_ISDIR(to_tell->i_mode) ? to_tell : NULL; + struct inode *dir = file_name ? to_tell : NULL; struct mount *mnt = NULL; struct inode *child = NULL; int ret = 0; diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 9bd75d0582b4..d94a50e0445a 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -123,9 +123,7 @@ struct mem_cgroup; * @data_type: type of object for fanotify_data_XXX() accessors * @dir: optional directory associated with event - * if @file_name is not NULL, this is the directory that - * @file_name is relative to. Otherwise, @dir is the object - * inode if event happened on directory and NULL if event - * happenned on a non-directory. + * @file_name is relative to * @file_name: optional file name associated with event * @cookie: inotify rename cookie * @iter_info: array of marks from this group that are interested in the event From patchwork Wed Jul 22 12:58:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A841513B1 for ; Wed, 22 Jul 2020 12:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BF1420787 for ; Wed, 22 Jul 2020 12:59:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BR8i3I/I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732395AbgGVM7N (ORCPT ); Wed, 22 Jul 2020 08:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732383AbgGVM7M (ORCPT ); Wed, 22 Jul 2020 08:59:12 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E68D9C0619DE for ; Wed, 22 Jul 2020 05:59:11 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id o8so1849108wmh.4 for ; Wed, 22 Jul 2020 05:59:11 -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=U4hE0z0mT1JIFl7L7587W+MGDvyQ1LjWWxTwG/xOIbU=; b=BR8i3I/IssWovvDF9+6355Ta/WFj7W1v7Ju3XyZnQSmXuCZLGmBg+9xNGmVsrIWVyh yXFJkvCXZOJGTUGUkJfiR9XZFFvypuU0zwwUt+YVfoFXFFbUTEoYJ7IaBK0bjIehU1kq hWQEnpnGSIO7mIjlr4Tevk4VuAw7esZPaZetj4geD+AleYqRF5M+ULNJ5uuh1Oc3pULK x72nQgRt36Nd0UhEiDuHvi28ANTd7SPsbYsggr8azkTpEKXxyWCzv6vLWfTWn8+u80QA SNyjFSWaMoQTcQkAABOUEHqufirVXjEa5xwDri/i+67CNbuFgo/ZNSZxvyJyK0sxlbp5 YASg== 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=U4hE0z0mT1JIFl7L7587W+MGDvyQ1LjWWxTwG/xOIbU=; b=eLyZPeAN0hTjq94e7Humru5ZrqQh7hgiBzIon8iOESEJHE31tHv1smnB4JnG96WPr7 rjhhLdRo+qz83uyQ9NdI+jdCEtsE0PhN12KBglTO1PzmutFcQiq4IEWl9kpe+GIu0x9o pdFCSBvRrJEIhDQUQWw7g5P/tv28e9xjWPqQRqa0onOGBr+K8O5N+djlNeUf5hubOpWv 6FG4whPa3jViNzO1bzEQQ0cXcbmpQpNBnJc3aguqz30fltGH8IcAKqinUuE7n/hoh1Lt rwCfsqZnyr8Jle35H/11XeOTikZCqm805DSbl5O4aAJmShUJ2yPD/2ZlxIuZi5/5cn1N XRRA== X-Gm-Message-State: AOAM530VcimO13gqOhX3GLUyPvWQF2VF+C2TzZGLZoYTbe5ZXUATQQB3 hSLm/hwiUkiYddkoGhAGL5nHK0f2 X-Google-Smtp-Source: ABdhPJwTOcilqyCTjv38lnB4+bRB8pkCcJeoG2GgkEpf9cOhPRw2eCznPUYyuzcBpqcZRi2ekRQjkw== X-Received: by 2002:a7b:cd83:: with SMTP id y3mr8332385wmj.105.1595422750561; Wed, 22 Jul 2020 05:59:10 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:10 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 6/9] fsnotify: pass dir and inode arguments to fsnotify() Date: Wed, 22 Jul 2020 15:58:46 +0300 Message-Id: <20200722125849.17418-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The arguments of fsnotify() are overloaded and mean different things for different event types. Replace the to_tell argument with separate arguments @dir and @inode, because we may be sending to both dir and child. Using the @data argument to pass the child is not enough, because dirent events pass this argument (for audit), but we do not report to child. Document the new fsnotify() function argumenets. Signed-off-by: Amir Goldstein --- fs/kernfs/file.c | 5 +-- fs/notify/fsnotify.c | 54 ++++++++++++++++++++++---------- include/linux/fsnotify.h | 9 +++--- include/linux/fsnotify_backend.h | 10 +++--- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c index 1d185bffc52f..f277d023ebcd 100644 --- a/fs/kernfs/file.c +++ b/fs/kernfs/file.c @@ -902,8 +902,9 @@ static void kernfs_notify_workfn(struct work_struct *work) if (parent) { p_inode = ilookup(info->sb, kernfs_ino(parent)); if (p_inode) { - fsnotify(p_inode, FS_MODIFY | FS_EVENT_ON_CHILD, - inode, FSNOTIFY_EVENT_INODE, &name, 0); + fsnotify(FS_MODIFY | FS_EVENT_ON_CHILD, + inode, FSNOTIFY_EVENT_INODE, + p_inode, &name, inode, 0); iput(p_inode); } diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 834775f61f6b..3b805e05c02d 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -179,7 +179,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, struct dentry *parent; bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED; __u32 p_mask; - struct inode *p_inode; + struct inode *p_inode = NULL; struct name_snapshot name; struct qstr *file_name = NULL; int ret = 0; @@ -213,14 +213,13 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, WARN_ON_ONCE(inode != fsnotify_data_inode(data, data_type)); /* Notify both parent and child with child name info */ - inode = p_inode; take_dentry_name_snapshot(&name, dentry); file_name = &name.name; mask |= FS_EVENT_ON_CHILD; } notify: - ret = fsnotify(inode, mask, data, data_type, file_name, 0); + ret = fsnotify(mask, data, data_type, p_inode, file_name, inode, 0); if (file_name) release_dentry_name_snapshot(&name); @@ -354,18 +353,31 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) } /* - * This is the main call to fsnotify. The VFS calls into hook specific functions - * in linux/fsnotify.h. Those functions then in turn call here. Here will call - * out to all of the registered fsnotify_group. Those groups can then use the - * notification event in whatever means they feel necessary. + * fsnotify - This is the main call to fsnotify. + * + * The VFS calls into hook specific functions in linux/fsnotify.h. + * Those functions then in turn call here. Here will call out to all of the + * registered fsnotify_group. Those groups can then use the notification event + * in whatever means they feel necessary. + * + * @mask: event type and flags + * @data: object that event happened on + * @data_type: type of object for fanotify_data_XXX() accessors + * @dir: optional directory associated with event - + * if @file_name is not NULL, this is the directory that + * @file_name is relative to + * @file_name: optional file name associated with event + * @inode: optional inode associated with event - + * either @dir or @inode must be non-NULL. + * if both are non-NULL event may be reported to both. + * @cookie: inotify rename cookie */ -int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, - const struct qstr *file_name, u32 cookie) +int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, + const struct qstr *file_name, struct inode *inode, u32 cookie) { const struct path *path = fsnotify_data_path(data, data_type); struct fsnotify_iter_info iter_info = {}; - struct super_block *sb = to_tell->i_sb; - struct inode *dir = file_name ? to_tell : NULL; + struct super_block *sb; struct mount *mnt = NULL; struct inode *child = NULL; int ret = 0; @@ -374,8 +386,18 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, if (path) mnt = real_mount(path->mnt); - if (mask & FS_EVENT_ON_CHILD) - child = fsnotify_data_inode(data, data_type); + if (!inode) { + /* Dirent event - report on TYPE_INODE to dir */ + inode = dir; + } else if (mask & FS_EVENT_ON_CHILD) { + /* + * Event on child - report on TYPE_INODE to dir + * and on TYPE_CHILD to child. + */ + child = inode; + inode = dir; + } + sb = inode->i_sb; /* * Optimization: srcu_read_lock() has a memory barrier which can @@ -384,12 +406,12 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, * SRCU because we have no references to any objects and do not * need SRCU to keep them "alive". */ - if (!to_tell->i_fsnotify_marks && !sb->s_fsnotify_marks && + if (!inode->i_fsnotify_marks && !sb->s_fsnotify_marks && (!mnt || !mnt->mnt_fsnotify_marks) && (!child || !child->i_fsnotify_marks)) return 0; - marks_mask = to_tell->i_fsnotify_mask | sb->s_fsnotify_mask; + marks_mask = inode->i_fsnotify_mask | sb->s_fsnotify_mask; if (mnt) marks_mask |= mnt->mnt_fsnotify_mask; if (child) @@ -407,7 +429,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_type, iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = - fsnotify_first_mark(&to_tell->i_fsnotify_marks); + fsnotify_first_mark(&inode->i_fsnotify_marks); iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = fsnotify_first_mark(&sb->s_fsnotify_marks); if (mnt) { diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 01b71ad91339..d9b26c6552ee 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -23,13 +23,14 @@ * have changed (i.e. renamed over). * * Unlike fsnotify_parent(), the event will be reported regardless of the - * FS_EVENT_ON_CHILD mask on the parent inode. + * FS_EVENT_ON_CHILD mask on the parent inode and will not be reported if only + * the child is interested and not the parent. */ static inline void fsnotify_name(struct inode *dir, __u32 mask, struct inode *child, const struct qstr *name, u32 cookie) { - fsnotify(dir, mask, child, FSNOTIFY_EVENT_INODE, name, cookie); + fsnotify(mask, child, FSNOTIFY_EVENT_INODE, dir, name, NULL, cookie); } static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry, @@ -43,7 +44,7 @@ static inline void fsnotify_inode(struct inode *inode, __u32 mask) if (S_ISDIR(inode->i_mode)) mask |= FS_ISDIR; - fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify(mask, inode, FSNOTIFY_EVENT_INODE, NULL, NULL, inode, 0); } /* Notify this dentry's parent about a child's events. */ @@ -67,7 +68,7 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, return __fsnotify_parent(dentry, mask, data, data_type); notify_child: - return fsnotify(inode, mask, data, data_type, NULL, 0); + return fsnotify(mask, data, data_type, NULL, NULL, inode, 0); } /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index d94a50e0445a..32104cfc27a5 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -398,8 +398,9 @@ struct fsnotify_mark { /* called from the vfs helpers */ /* main fsnotify call to send events */ -extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, - int data_type, const struct qstr *name, u32 cookie); +extern int fsnotify(__u32 mask, const void *data, int data_type, + struct inode *dir, const struct qstr *name, + struct inode *inode, u32 cookie); extern int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, int data_type); extern void __fsnotify_inode_delete(struct inode *inode); @@ -569,8 +570,9 @@ static inline void fsnotify_init_event(struct fsnotify_event *event, #else -static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, - int data_type, const struct qstr *name, u32 cookie) +static inline int fsnotify(__u32 mask, const void *data, int data_type, + struct inode *dir, const struct qstr *name, + struct inode *inode, u32 cookie) { return 0; } From patchwork Wed Jul 22 12:58:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4954E13A4 for ; Wed, 22 Jul 2020 12:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 305C920729 for ; Wed, 22 Jul 2020 12:59:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uZoGXfwF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732396AbgGVM7O (ORCPT ); Wed, 22 Jul 2020 08:59:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbgGVM7N (ORCPT ); Wed, 22 Jul 2020 08:59:13 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27180C0619DC for ; Wed, 22 Jul 2020 05:59:13 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id c80so1859905wme.0 for ; Wed, 22 Jul 2020 05:59:13 -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=7eTqHQLUCWKWQRufe18gQN1hCUN7B4GBXZpVXhLVG68=; b=uZoGXfwFgsnWFZYkS1bl2JgqTctJuvHLZ3HGRZkLhMJFdlyEfZGtHPZz05EjfPSspA yv0fXoHbxLWtWviL4AxVFYsl7E5ygghLhCLSetf9QsJSsseFlsnD6E8KBmtpUzlKMQO2 jhg75FjCLvgWAKl8p+6bdVONFiddqvdAIQf6fi2LRYbxweyq+oSiaVgnsbzV81N0VzDD E9pL2Xn6iyDed3JpCbaktZmzVNJakMt9jQrVEWsDHWY7n+HerLvCx1ra9bzq1YL5Z4CV US5wL0ZUIeDXspca3+cDEkHjaIa59uKFT52is3RvR0G4v0GoGz6yLw7+TP3IQOok7F87 2jkQ== 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=7eTqHQLUCWKWQRufe18gQN1hCUN7B4GBXZpVXhLVG68=; b=pQUk28kJhwtpByIvcsBoKYXbtAbPNHxq19YwVJMP6HO5cW7QRpIhwCCE2phO70/bvf VL5nUUIRRNlqsFlsp8fHaiUy7Ro9uYn3F8MtADnt3JRcxO59TPGKdi7lD8tNf1ptz6bD Ssih20kiVVc+T+z4UHLT5AhVbFgc9MXwkYwLZrxDNaXTfUf7FY6C9sd/j3jWc5clAqUE zvTmu5eSxIkE0hMqI37qUxBwKjEkcQjHOWPp3UmLMamfRbzMftm/3ZEcb9Kl7Wv4Mg11 ZBmzdpQlbEoLQHAH5bQDaIJFbLkYmEUqICROedtxjuOWoOl9ZgAz8HSzWc3/ko+QXb4j jXfw== X-Gm-Message-State: AOAM530SSyZUxJOJ2LyDdfWSmFogb7KitzMgLlm5jBuyzkanBiITzMDK /vZRK2qUt2Tddy++v/1GTec= X-Google-Smtp-Source: ABdhPJx+3nx4pY7+/fAMD2IB9tpJh3AcbqTmVB4UHWFZxqto0w1AtwPkZx58zPG8Wss1eHiNFZyBNA== X-Received: by 2002:a1c:2bc1:: with SMTP id r184mr9037312wmr.133.1595422751824; Wed, 22 Jul 2020 05:59:11 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:11 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 7/9] fsnotify: fix merge with parent mark masks Date: Wed, 22 Jul 2020 15:58:47 +0300 Message-Id: <20200722125849.17418-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When reporting event with parent/name info, we should not merge parent's mark mask and ignore mask, unless the parent has the flag FS_EVENT_ON_CHILD in the mask. Therefore, in fsnotify_parent(), set the FS_EVENT_ON_CHILD flag in event mask only if parent is watching and use this flag to decide if the parent mark masks should be merged with child/sb/mount marks. After this change, even groups that do not subscribe to events on children could get an event with mark iterator type TYPE_CHILD and without mark iterator type TYPE_INODE if fanotify has marks on the same objects. dnotify and inotify event handlers can already cope with that situation. audit does not subscribe to events that are possible on child, so won't get to this situation. nfsd does not access the marks iterator from its event handler at the moment, so it is not affected. This is a bit too fragile, so we should prepare all groups to cope with mark type TYPE_CHILD preferably using a generic helper. Link: https://lore.kernel.org/linux-fsdevel/20200716223441.GA5085@quack2.suse.cz/ Fixes: ecf13b5f8fd6 ("fsnotify: send event with parent/name info to sb/mount/non-dir marks") Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fsnotify.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 03e3dce2a97c..3336157d895d 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -538,7 +538,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, * in addition to reporting the parent fid and maybe child name. */ if ((fid_mode & FAN_REPORT_FID) && - (mask & FAN_EVENT_ON_CHILD) && !(mask & FAN_ONDIR)) + id != dirid && !(mask & FAN_ONDIR)) child = id; id = dirid; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 3b805e05c02d..494d5d70323f 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -215,7 +215,8 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, /* Notify both parent and child with child name info */ take_dentry_name_snapshot(&name, dentry); file_name = &name.name; - mask |= FS_EVENT_ON_CHILD; + if (parent_watched) + mask |= FS_EVENT_ON_CHILD; } notify: @@ -391,8 +392,8 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, inode = dir; } else if (mask & FS_EVENT_ON_CHILD) { /* - * Event on child - report on TYPE_INODE to dir - * and on TYPE_CHILD to child. + * Event on child - report on TYPE_INODE to dir if it is + * watching children and on TYPE_CHILD to child. */ child = inode; inode = dir; @@ -406,14 +407,17 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, * SRCU because we have no references to any objects and do not * need SRCU to keep them "alive". */ - if (!inode->i_fsnotify_marks && !sb->s_fsnotify_marks && + if (!sb->s_fsnotify_marks && (!mnt || !mnt->mnt_fsnotify_marks) && + (!inode || !inode->i_fsnotify_marks) && (!child || !child->i_fsnotify_marks)) return 0; - marks_mask = inode->i_fsnotify_mask | sb->s_fsnotify_mask; + marks_mask = sb->s_fsnotify_mask; if (mnt) marks_mask |= mnt->mnt_fsnotify_mask; + if (inode) + marks_mask |= inode->i_fsnotify_mask; if (child) marks_mask |= child->i_fsnotify_mask; @@ -428,14 +432,16 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, iter_info.srcu_idx = srcu_read_lock(&fsnotify_mark_srcu); - iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = - fsnotify_first_mark(&inode->i_fsnotify_marks); iter_info.marks[FSNOTIFY_OBJ_TYPE_SB] = fsnotify_first_mark(&sb->s_fsnotify_marks); if (mnt) { iter_info.marks[FSNOTIFY_OBJ_TYPE_VFSMOUNT] = fsnotify_first_mark(&mnt->mnt_fsnotify_marks); } + if (inode) { + iter_info.marks[FSNOTIFY_OBJ_TYPE_INODE] = + fsnotify_first_mark(&inode->i_fsnotify_marks); + } if (child) { iter_info.marks[FSNOTIFY_OBJ_TYPE_CHILD] = fsnotify_first_mark(&child->i_fsnotify_marks); From patchwork Wed Jul 22 12:58:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53F0813B1 for ; Wed, 22 Jul 2020 12:59:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35E2920729 for ; Wed, 22 Jul 2020 12:59:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TKwHJ8mt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732398AbgGVM7P (ORCPT ); Wed, 22 Jul 2020 08:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbgGVM7P (ORCPT ); Wed, 22 Jul 2020 08:59:15 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA55C0619DC for ; Wed, 22 Jul 2020 05:59:14 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id w3so1903306wmi.4 for ; Wed, 22 Jul 2020 05:59:14 -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=V2oZQN2akVvLYSP+sJpUUnq/OiaARIQGx4WrZ4Cv6Zk=; b=TKwHJ8mta58irgRN2P+ewWVkiGtogDhdSUtTQ0x0mp87mivGIydmPj2xAKEAYagUM6 H9YgkSl75fIcM77PqzROY0s4RywBCQOqt9qOJ9ZVK+jd4FubmP716O3rVKyvwRZdOP7J gSM7/f+Vbwk8IZobC25QZBn47gaMXZECCXK/erO1d49ZAIKsRVZs9efA/HZdNwHFI35E J1ZINs8jIMQmPEwajgPFI8vK2rGWqXi8NX5WxFpZNQ018LmVzXt29c/siswpNsk1IS5c YxExhQexWD8GqDDKOGWQ1872d5APd+cUCGXffy5uRyBT2XzTq7GeRow71zuWMlQXQ4QV xnHQ== 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=V2oZQN2akVvLYSP+sJpUUnq/OiaARIQGx4WrZ4Cv6Zk=; b=bhIcheP1Bwj/9K6ZTKhzPzTi5Jg5dxaXtszDhlMVKJcTBlofx4ExcHlZGYW2Vfzn26 hhRzef4MoMmTvAmAh/qFWCDP1hg68spqtQ5REE6HgM28E4SsA0K+J8oVC1kQJ9ezjSm0 muQchjO7rQbvdVSVejiltfROsb7e668sY5sjpvHPEAKH9EZzxBmRQi/rWuX+QuoYxB8i V0PYdo58NTnsvfDww9S8ukoukfY4TC6FB/ZikGJUCKDMJm4APdOmA0EIZRd31QiqI30g t398AFENMU207TDBHcECw61wHspHW1KMqUuOxbCtkOiP7R7WN6lDcuS48fkNyUxxhuOE E6lw== X-Gm-Message-State: AOAM533m6IRU52lBWQttwLY8UK9qKIDAXeu3z9Q+xqtVOFZ2WZtBLuh4 tbUwat0tGVQ5eo81ShudjUM= X-Google-Smtp-Source: ABdhPJy1YKQvUb0M/a+RrJE7ERWTbgIsLhk91zMJTc+5yJmRZJ1QJldKiFSXT2/Ki0fVYIg2pocZLA== X-Received: by 2002:a7b:c747:: with SMTP id w7mr1737047wmk.136.1595422753213; Wed, 22 Jul 2020 05:59:13 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:12 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 8/9] fsnotify: create method handle_inode_event() in fsnotify_operations Date: Wed, 22 Jul 2020 15:58:48 +0300 Message-Id: <20200722125849.17418-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The method handle_event() grew a lot of complexity due to the design of fanotify and merging of ignore masks. Most backends do not care about this complex functionality, so we can hide this complexity from them. Introduce a method handle_inode_event() that serves those backends and passes a single inode mark and less arguments. This change converts all backends except fanotify and inotify to use the simplified handle_inode_event() method. In pricipal, inotify could have also used the new method, but that would require passing more arguments on the simple helper (data, data_type, cookie), so we leave it with the handle_event() method. Suggested-by: Jan Kara Signed-off-by: Amir Goldstein --- fs/nfsd/filecache.c | 12 +++----- fs/notify/dnotify/dnotify.c | 38 +++++------------------ fs/notify/fsnotify.c | 52 ++++++++++++++++++++++++++++++-- include/linux/fsnotify_backend.h | 19 ++++++++++-- kernel/audit_fsnotify.c | 20 +++++------- kernel/audit_tree.c | 10 +++--- kernel/audit_watch.c | 17 +++++------ 7 files changed, 97 insertions(+), 71 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index bbc7892d2928..c8b9d2667ee6 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -598,14 +598,10 @@ static struct notifier_block nfsd_file_lease_notifier = { }; static int -nfsd_file_fsnotify_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *file_name, u32 cookie, - struct fsnotify_iter_info *iter_info) +nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *name) { - struct inode *inode = fsnotify_data_inode(data, data_type); - trace_nfsd_file_fsnotify_handle_event(inode, mask); /* Should be no marks on non-regular files */ @@ -626,7 +622,7 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_group *group, u32 mask, static const struct fsnotify_ops nfsd_file_fsnotify_ops = { - .handle_event = nfsd_file_fsnotify_handle_event, + .handle_inode_event = nfsd_file_fsnotify_handle_event, .free_mark = nfsd_file_mark_free, }; diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index ca78d3f78da8..5dcda8f20c04 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -70,8 +70,9 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark) * destroy the dnotify struct if it was not registered to receive multiple * events. */ -static void dnotify_one_event(struct fsnotify_group *group, u32 mask, - struct fsnotify_mark *inode_mark) +static int dnotify_handle_event(struct fsnotify_mark *inode_mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *name) { struct dnotify_mark *dn_mark; struct dnotify_struct *dn; @@ -79,6 +80,10 @@ static void dnotify_one_event(struct fsnotify_group *group, u32 mask, struct fown_struct *fown; __u32 test_mask = mask & ~FS_EVENT_ON_CHILD; + /* not a dir, dnotify doesn't care */ + if (!dir && !(mask & FS_ISDIR)) + return 0; + dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark); spin_lock(&inode_mark->lock); @@ -100,33 +105,6 @@ static void dnotify_one_event(struct fsnotify_group *group, u32 mask, } spin_unlock(&inode_mark->lock); -} - -static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *file_name, u32 cookie, - struct fsnotify_iter_info *iter_info) -{ - struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); - struct fsnotify_mark *child_mark = fsnotify_iter_child_mark(iter_info); - - /* not a dir, dnotify doesn't care */ - if (!dir && !(mask & FS_ISDIR)) - return 0; - - if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info))) - return 0; - - /* - * Some events can be sent on both parent dir and subdir marks - * (e.g. DN_ATTRIB). If both parent dir and subdir are watching, - * report the event once to parent dir and once to subdir. - */ - if (inode_mark) - dnotify_one_event(group, mask, inode_mark); - if (child_mark) - dnotify_one_event(group, mask, child_mark); return 0; } @@ -143,7 +121,7 @@ static void dnotify_free_mark(struct fsnotify_mark *fsn_mark) } static const struct fsnotify_ops dnotify_fsnotify_ops = { - .handle_event = dnotify_handle_event, + .handle_inode_event = dnotify_handle_event, .free_mark = dnotify_free_mark, }; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 494d5d70323f..a960ec3a569a 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -230,6 +230,49 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, } EXPORT_SYMBOL_GPL(__fsnotify_parent); +static int fsnotify_handle_event(struct fsnotify_group *group, __u32 mask, + const void *data, int data_type, + struct inode *dir, const struct qstr *name, + u32 cookie, struct fsnotify_iter_info *iter_info) +{ + struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); + struct fsnotify_mark *child_mark = fsnotify_iter_child_mark(iter_info); + struct inode *inode = fsnotify_data_inode(data, data_type); + const struct fsnotify_ops *ops = group->ops; + int ret; + + if (WARN_ON_ONCE(!ops->handle_inode_event)) + return 0; + + if (WARN_ON_ONCE(fsnotify_iter_sb_mark(iter_info)) || + WARN_ON_ONCE(fsnotify_iter_vfsmount_mark(iter_info))) + return 0; + + /* + * An event can be sent on child mark iterator instead of inode mark + * iterator because of other groups that have interest of this inode + * and have marks on both parent and child. We can simplify this case. + */ + if (!inode_mark) { + inode_mark = child_mark; + child_mark = NULL; + dir = NULL; + name = NULL; + } + + ret = ops->handle_inode_event(inode_mark, mask, inode, dir, name); + if (ret || !child_mark) + return ret; + + /* + * Some events can be sent on both parent dir and child marks + * (e.g. FS_ATTRIB). If both parent dir and child are watching, + * report the event once to parent dir with name and once to child + * without name. + */ + return ops->handle_inode_event(child_mark, mask, inode, NULL, NULL); +} + static int send_to_group(__u32 mask, const void *data, int data_type, struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info) @@ -275,8 +318,13 @@ static int send_to_group(__u32 mask, const void *data, int data_type, if (!(test_mask & marks_mask & ~marks_ignored_mask)) return 0; - return group->ops->handle_event(group, mask, data, data_type, dir, - file_name, cookie, iter_info); + if (group->ops->handle_event) { + return group->ops->handle_event(group, mask, data, data_type, dir, + file_name, cookie, iter_info); + } + + return fsnotify_handle_event(group, mask, data, data_type, dir, + file_name, cookie, iter_info); } static struct fsnotify_mark *fsnotify_first_mark(struct fsnotify_mark_connector **connp) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 32104cfc27a5..f8529a3a2923 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -128,17 +128,30 @@ struct mem_cgroup; * @cookie: inotify rename cookie * @iter_info: array of marks from this group that are interested in the event * + * handle_inode_event - simple variant of handle_event() for groups that only + * have inode marks and don't have ignore mask + * @mark: mark to notify + * @mask: event type and flags + * @inode: inode that event happened on + * @dir: optional directory associated with event - + * if @file_name is not NULL, this is the directory that + * @file_name is relative to. + * @file_name: optional file name associated with event + * * free_group_priv - called when a group refcnt hits 0 to clean up the private union * freeing_mark - called when a mark is being destroyed for some reason. The group - * MUST be holding a reference on each mark and that reference must be - * dropped in this function. inotify uses this function to send - * userspace messages that marks have been removed. + * MUST be holding a reference on each mark and that reference must be + * dropped in this function. inotify uses this function to send + * userspace messages that marks have been removed. */ struct fsnotify_ops { int (*handle_event)(struct fsnotify_group *group, u32 mask, const void *data, int data_type, struct inode *dir, const struct qstr *file_name, u32 cookie, struct fsnotify_iter_info *iter_info); + int (*handle_inode_event)(struct fsnotify_mark *mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *file_name); void (*free_group_priv)(struct fsnotify_group *group); void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group); void (*free_event)(struct fsnotify_event *event); diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index bd3a6b79316a..bfcfcd61adb6 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -152,35 +152,31 @@ static void audit_autoremove_mark_rule(struct audit_fsnotify_mark *audit_mark) } /* Update mark data in audit rules based on fsnotify events. */ -static int audit_mark_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *dname, u32 cookie, - struct fsnotify_iter_info *iter_info) +static int audit_mark_handle_event(struct fsnotify_mark *inode_mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *dname) { - struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); struct audit_fsnotify_mark *audit_mark; - const struct inode *inode = fsnotify_data_inode(data, data_type); audit_mark = container_of(inode_mark, struct audit_fsnotify_mark, mark); - BUG_ON(group != audit_fsnotify_group); - - if (WARN_ON(!inode)) + if (WARN_ON_ONCE(inode_mark->group != audit_fsnotify_group) || + WARN_ON_ONCE(!inode)) return 0; if (mask & (FS_CREATE|FS_MOVED_TO|FS_DELETE|FS_MOVED_FROM)) { if (audit_compare_dname_path(dname, audit_mark->path, AUDIT_NAME_FULL)) return 0; audit_update_mark(audit_mark, inode); - } else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF)) + } else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF)) { audit_autoremove_mark_rule(audit_mark); + } return 0; } static const struct fsnotify_ops audit_mark_fsnotify_ops = { - .handle_event = audit_mark_handle_event, + .handle_inode_event = audit_mark_handle_event, .free_mark = audit_fsnotify_free_mark, }; diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index 2ce2ac1ce100..025d24abf15d 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c @@ -1037,11 +1037,9 @@ static void evict_chunk(struct audit_chunk *chunk) audit_schedule_prune(); } -static int audit_tree_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *file_name, u32 cookie, - struct fsnotify_iter_info *iter_info) +static int audit_tree_handle_event(struct fsnotify_mark *mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *file_name) { return 0; } @@ -1070,7 +1068,7 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *mark, } static const struct fsnotify_ops audit_tree_ops = { - .handle_event = audit_tree_handle_event, + .handle_inode_event = audit_tree_handle_event, .freeing_mark = audit_tree_freeing_mark, .free_mark = audit_tree_destroy_watch, }; diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c index e23d54bcc587..246e5ba704c0 100644 --- a/kernel/audit_watch.c +++ b/kernel/audit_watch.c @@ -464,20 +464,17 @@ void audit_remove_watch_rule(struct audit_krule *krule) } /* Update watch data in audit rules based on fsnotify events. */ -static int audit_watch_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *dname, u32 cookie, - struct fsnotify_iter_info *iter_info) +static int audit_watch_handle_event(struct fsnotify_mark *inode_mark, u32 mask, + struct inode *inode, struct inode *dir, + const struct qstr *dname) { - struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); - const struct inode *inode = fsnotify_data_inode(data, data_type); struct audit_parent *parent; parent = container_of(inode_mark, struct audit_parent, mark); - BUG_ON(group != audit_watch_group); - WARN_ON(!inode); + if (WARN_ON_ONCE(inode_mark->group != audit_watch_group) || + WARN_ON_ONCE(!inode)) + return 0; if (mask & (FS_CREATE|FS_MOVED_TO) && inode) audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0); @@ -490,7 +487,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group, u32 mask, } static const struct fsnotify_ops audit_watch_fsnotify_ops = { - .handle_event = audit_watch_handle_event, + .handle_inode_event = audit_watch_handle_event, .free_mark = audit_watch_free_mark, }; From patchwork Wed Jul 22 12:58:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 11678459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35C0713B1 for ; Wed, 22 Jul 2020 12:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DC5E20787 for ; Wed, 22 Jul 2020 12:59:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z10qrMUd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732403AbgGVM7Q (ORCPT ); Wed, 22 Jul 2020 08:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbgGVM7Q (ORCPT ); Wed, 22 Jul 2020 08:59:16 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29E8C0619DC for ; Wed, 22 Jul 2020 05:59:15 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id 88so1827264wrh.3 for ; Wed, 22 Jul 2020 05:59:15 -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=LDIZNgi94GiXOtORkm5SjaKnLd9AG9vo4a42BVfLa+w=; b=Z10qrMUd5wwTiwqazU7e1BKBn4UrbKmyTBPUW+87/xmF3X1irHRRiK42otsRnv7TGL NPwx+OYwhTIcSdf/WOT2KUVoaC9Up3EZy67466pzLsYt4roI12JlwXEwOilo8cE54hnt TFVeukq8WGPQFEZYNHI9qIAerd07igm/qlm/I7Q1a534usaPz9I9qwFh7f3PIX+lBE8S mWC0N00M53rFJcCUVptN1KmVXcKF6dcjKhJSBQ90v1qmCqGNRxcRPQD138RsdRECh7am wQLlTMe56vfpLUJrxh98t1H4PijDEmK7f/AjV40Nrx/b0rowiRmLh1GbqlmK6o2vrMHE LaTg== 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=LDIZNgi94GiXOtORkm5SjaKnLd9AG9vo4a42BVfLa+w=; b=uVwedmXL3ac4LN4009snmKbpI9HZ1vtS+A7qFu3T/3Ktb9uVMYecmoUHO/ZFgRmKKn 6s/n2G2dNCAhNKdP0+kVZsD2ZMqjZm5jgYsUS99JULEkCGR5IEue7sNYy6Bk6XO1ub0i DhMkqjYHLj1AzLbLoIwi27Y7q6J7q6NkwijXRDGPADjsabNoQqsU8s8JNVu5GkN3xLdp c9i0OUEPoxQcfyOBH76XZAweO6hhB3odUmoTYtTOop1nrER4Rt8w3YJO6xIjHFRinKC+ OCDVm+F9075bg1oUJp2a214bBm/EFSB4NTmPNW0eum6nZKqa9NkZVUZ/J8JC/uBq9dDh xWSg== X-Gm-Message-State: AOAM532RgKdEpKUyR8lLVvIEgvlX2i1UQy1wS9JFXCM1gpPHxzEW8TUk 8oiG/sDf7e4HMt09DmF5slE3y9yc X-Google-Smtp-Source: ABdhPJx51L5Tw5ehb3BYPCtYsCJyYQS9zezZVsqQ9qRGC2DmyCE7z6QzP8Q+erk5oDnE2EGGfiA7iw== X-Received: by 2002:adf:e486:: with SMTP id i6mr16879281wrm.258.1595422754414; Wed, 22 Jul 2020 05:59:14 -0700 (PDT) Received: from localhost.localdomain ([31.210.180.214]) by smtp.gmail.com with ESMTPSA id s4sm35487744wre.53.2020.07.22.05.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 05:59:13 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 9/9] fsnotify: pass inode to fsnotify_parent() Date: Wed, 22 Jul 2020 15:58:49 +0300 Message-Id: <20200722125849.17418-10-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722125849.17418-1-amir73il@gmail.com> References: <20200722125849.17418-1-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org We can get inode by dereferenceing dentry->d_inode, but that may have performance impact in the fast path of non watched file. Kernel test robot reported a performance regression in concurrent open workload, so maybe that can fix it. Reported-by: kernel test robot Fixes: c738fbabb0ff ("fsnotify: fold fsnotify() call into fsnotify_parent()") Signed-off-by: Amir Goldstein --- include/linux/fsnotify.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index d9b26c6552ee..4a9b2f5b819b 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -49,10 +49,9 @@ static inline void fsnotify_inode(struct inode *inode, __u32 mask) /* Notify this dentry's parent about a child's events. */ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, - const void *data, int data_type) + const void *data, int data_type, + struct inode *inode) { - struct inode *inode = d_inode(dentry); - if (S_ISDIR(inode->i_mode)) { mask |= FS_ISDIR; @@ -77,7 +76,8 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask, */ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) { - fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE); + fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE, + d_inode(dentry)); } static inline int fsnotify_file(struct file *file, __u32 mask) @@ -87,7 +87,8 @@ static inline int fsnotify_file(struct file *file, __u32 mask) if (file->f_mode & FMODE_NONOTIFY) return 0; - return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); + return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH, + file_inode(file)); } /* Simple call site for access decisions */