Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5060832pxb; Thu, 14 Oct 2021 18:18:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzE5XvpZnx8mQw1t7rPVIwGVjbcpZEFKGBE0pPnZkLFf+d9bsnAlgpCguxWTIdKIrYV3RrD X-Received: by 2002:a17:902:e748:b0:13f:205a:f93f with SMTP id p8-20020a170902e74800b0013f205af93fmr8209636plf.29.1634260725428; Thu, 14 Oct 2021 18:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634260725; cv=none; d=google.com; s=arc-20160816; b=Kegqli3J41+MJc1IWyhM4FWLZv5cXIr2Y6MUA2IIgbR1qh84kbQ7sbZ/pwDqkHa+WG TJctGtMlYgvKvtbvFOaPT2GnusmEDxXAuyblRUjO9WGoZf1Jwuy/O7bOg1R4SIdwGV5h RKyEr7QsphgbppHLSaE6mK6fMv9RpsoJNAQ7xEikI2uyH6xxFuvPxgWk5zggC/KszW+c S9dYQTwtPFltx3fGkYsSwRU4pH8QOu9PM0xITBAvVpOp0hjlMBB3otdrbFEG++Cc3oek tWg/kyd6WnxlaQBRo0zjUdSzvOiGwFvkPyRswkJAduFffwJ8d4xay7oBd8pP1Wz9gNRU 8HFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CA00TzU1eTMV1XHdY8U49Ay6LS5H9YSBwm7sOaBKvJY=; b=QEInjWFdGNnqywl8ydBHxwSZlc62OwsNaAnlGOJ/CwLTrSop8ukzXJCUeW62iZrQjA Oqqv/JyPtVqoJ3MOT9a+6O+g12uTk8oJyKgz/d42i8344E8Zx8w+JzPz8YO8ozeudD7H 37wOxgf/qfwjFdch/Tvr7lVJ4gIOGyPa79Uj+XcbGIh5TYIBgE3QAPmrKkBBK8b3C3Yx sHJ8WDNDJCE2pDvxz0UM4ld/lyn3r/cDBiotkWUkrSijMrVIRtaoJo0ZLJ71ZkS+qNdr cxkDHu0z5RMzHpjcWZxAxFBnGiiwcNLLLXCVp2JcWtzslFz5TTRPgdBKwwrqjrVCoJZJ Htvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si2984074pfu.364.2021.10.14.18.18.33; Thu, 14 Oct 2021 18:18:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbhJNVkR (ORCPT + 99 others); Thu, 14 Oct 2021 17:40:17 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54106 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233512AbhJNVkR (ORCPT ); Thu, 14 Oct 2021 17:40:17 -0400 Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id B21451F44F83; Thu, 14 Oct 2021 22:38:09 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, repnop@google.com, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v7 10/28] fsnotify: Retrieve super block from the data field Date: Thu, 14 Oct 2021 18:36:28 -0300 Message-Id: <20211014213646.1139469-11-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014213646.1139469-1-krisman@collabora.com> References: <20211014213646.1139469-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Some file system events (i.e. FS_ERROR) might not be associated with an inode or directory. For these, we can retrieve the super block from the data field. But, since the super_block is available in the data field on every event type, simplify the code to always retrieve it from there, through a new helper. Suggested-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi -- Changes since v6: - Always use data field for superblock retrieval Changes since v5: - add fsnotify_data_sb handle to retrieve sb from the data field. (jan) --- fs/notify/fsnotify.c | 7 +++---- include/linux/fsnotify_backend.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 963e6ce75b96..fde3a1115a17 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -455,16 +455,16 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) * @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. + * If @dir and @inode are both non-NULL, event may be + * reported to both. * @cookie: inotify rename 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 super_block *sb = fsnotify_data_sb(data, data_type); struct fsnotify_iter_info iter_info = {}; - struct super_block *sb; struct mount *mnt = NULL; struct inode *parent = NULL; int ret = 0; @@ -483,7 +483,6 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, */ parent = dir; } - sb = inode->i_sb; /* * Optimization: srcu_read_lock() has a memory barrier which can diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index b323d0c4b967..035438fe4a43 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -289,6 +289,21 @@ static inline const struct path *fsnotify_data_path(const void *data, } } +static inline struct super_block *fsnotify_data_sb(const void *data, + int data_type) +{ + switch (data_type) { + case FSNOTIFY_EVENT_INODE: + return ((struct inode *)data)->i_sb; + case FSNOTIFY_EVENT_DENTRY: + return ((struct dentry *)data)->d_sb; + case FSNOTIFY_EVENT_PATH: + return ((const struct path *)data)->dentry->d_sb; + default: + return NULL; + } +} + enum fsnotify_obj_type { FSNOTIFY_OBJ_TYPE_INODE, FSNOTIFY_OBJ_TYPE_PARENT, -- 2.33.0