Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3501328pxb; Mon, 18 Oct 2021 17:02:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF/liXpbfnfs+hplb1FaaWmJjnXCZP07A+fqelVwEzt65dYFoIDbn9bUqUkOOrBi1wFLfk X-Received: by 2002:a17:906:2cd5:: with SMTP id r21mr34412942ejr.435.1634601763015; Mon, 18 Oct 2021 17:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634601763; cv=none; d=google.com; s=arc-20160816; b=y23PAsIqSmLPoZKra2Yb1HMgX2vovAxPTb10pWGA8wx1hLuMj1OX2715r1mDlusL8U WtQCvsDbIFdKuCSBSLPrsQrhAzlL+0NNIkIFMDBMm7Fo47JAN1nuRtRAxHyWrEj0TmdV qBK6V9iGoEPGhu2Gx5uplGIUHyZjmYQ7afs85j7CDJxgmF8/J67v5H0Qrq43URrVSL/j XW6nBXC9mqEjZhUSF0ASZ1m0Y8dlrD7ZeBE1+stcFH+7mj8DkB1lgwrk4QUUSRkKxtRY 9bZTmrhWMArYCfEV3N6RcwZki5Kq9ug8fM0Ywsj9OH2aEzcv2jmYgL4Jko39ow2cUgkB yWlA== 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=/6FgtS2IRdLOmS6Mj9XMaUBjCZpRRDZWy2cVV33UFpc=; b=yf3hxEL9fHZXojrtoIubHpZFBAVyI9yXpaeMj/PQ0D64RUOisBvQdfdjFUk36YARU6 3TIcqveX02aSFkHlgOKHqL65qslsrATTFSAglymmsnZp9Z0iOqyEZqVoupVLMSThjdQr sDCsXHiQG/tQERRPHa1eFmdjEFebI6RueZ+fwArZtHRvZ4rckgQiOqCZR8el38rsX5pc 30kWu1S9CjwzeOXNAk6CnypUL2Ip8B3GX6Y/uU0OYgn/NUMoAUHEQW/CCClI7Aegyjek MDTHBsjqxfIRAhQf4kihs+qwzqVdBVrX9+WUXPxtya3FwZhelBzpwfrvsBUeZ+vnsz4S cOFw== 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 w7si26618976edd.351.2021.10.18.17.02.17; Mon, 18 Oct 2021 17:02:43 -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 S233878AbhJSADy (ORCPT + 99 others); Mon, 18 Oct 2021 20:03:54 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40742 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbhJSADw (ORCPT ); Mon, 18 Oct 2021 20:03:52 -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 8E71E1F41A9C; Tue, 19 Oct 2021 01:01:36 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v8 10/32] fsnotify: Retrieve super block from the data field Date: Mon, 18 Oct 2021 20:59:53 -0300 Message-Id: <20211019000015.1666608-11-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211019000015.1666608-1-krisman@collabora.com> References: <20211019000015.1666608-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 Reviewed-by: Amir Goldstein Reviewed-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