Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp930362pxj; Fri, 21 May 2021 02:28:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLWsv8gyAIuBEgwyIkwv/l3CfRntKlV54bIi9vmB6ZDORukGYQdlq4xK4YRbQlfd1e8BMF X-Received: by 2002:a17:906:914d:: with SMTP id y13mr9367609ejw.489.1621589286749; Fri, 21 May 2021 02:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621589286; cv=none; d=google.com; s=arc-20160816; b=OWJYnaCS5v0r7YjpsfEaxqSAq+BxtnGjGL94doNu0MbwP3KNjHP3me8SGxiQPHD2hd Yr5f5TYS+A4rklWnHQlVdK6Kyb+FbJPwRQxyiJWY3Pv1nfYaoDPXj8Lq58rw9lTZ5E6c W4TZPpS5z7apkYDtf4oD7PqN4FvxpFNbKziG6fuGOaAYd9wYB5Zx0kDeiwBaxxUZQO7i WIy+45g3qQ+cGzeiePGjC88CLBGuS0OtsfZfFRLo/HAiE6h4P/m0PwqMbqSBHL2nDwHF kAVDEJt2kQFDFxJGRMNwPT3p3j0bHhXJHx3RTrPp/5Rv+3aFh+2ymxnDVvMzvgrgbu3J 256g== 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=8ei6Kscj65ZeQH3KUaJ1sbedwkcn1Qg2fm652YU7Umk=; b=xqPX+A7KW/PRozLggP0jCyeKcJT39AYWz0MJ5OXkOEFZqkgLGb+5tRJo4zL837w1G7 9zGFjoAYIjzmln7YMj44N2on11l+xP++0Vl19ho8hI+R/m4UkpYD5co4LiqZhTXtkQ54 hEzwIJgb3Y7D2mHZ03gwa6AEL2Cnjt8Er5buXYtXScCeWqeTrWkA5UQVYNqpTSwKmVTx ljw3MsQJ2A47t7aQke0Ip/dqOXiAEQEfpOmfyYNsI/7jT+NqdXddGAFOfktqsv/wTrNr T5DG9Skj7+DRR92/N1Q1VbvD70/czfQ543E6hZIXKyKzYSwjn6/ypXRhNqNoYd3XjZa3 pdWA== 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 u8si5082555edd.67.2021.05.21.02.27.43; Fri, 21 May 2021 02:28:06 -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 S232906AbhEUCnZ (ORCPT + 99 others); Thu, 20 May 2021 22:43:25 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54836 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbhEUCnZ (ORCPT ); Thu, 20 May 2021 22:43:25 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id E18551F43D30 From: Gabriel Krisman Bertazi To: amir73il@gmail.com Cc: Gabriel Krisman Bertazi , kernel@collabora.com, "Darrick J . Wong" , Theodore Ts'o , Dave Chinner , jack@suse.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Subject: [PATCH 01/11] fanotify: Fold event size calculation to its own function Date: Thu, 20 May 2021 22:41:24 -0400 Message-Id: <20210521024134.1032503-2-krisman@collabora.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210521024134.1032503-1-krisman@collabora.com> References: <20210521024134.1032503-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Every time this function is invoked, it is immediately added to FAN_EVENT_METADATA_LEN, since there is no need to just calculate the length of info records. This minor clean up folds the rest of the calculation into the function, which now operates in terms of events, returning the size of the entire event, including metadata. Reviewed-by: Amir Goldstein Signed-off-by: Gabriel Krisman Bertazi --- Changes since v1: - rebased on top of hashing patches --- fs/notify/fanotify/fanotify_user.c | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 71fefb30e015..3ccdee3c9f1e 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -117,17 +117,24 @@ static int fanotify_fid_info_len(int fh_len, int name_len) return roundup(FANOTIFY_INFO_HDR_LEN + info_len, FANOTIFY_EVENT_ALIGN); } -static int fanotify_event_info_len(unsigned int fid_mode, - struct fanotify_event *event) +static size_t fanotify_event_len(struct fanotify_event *event, + unsigned int fid_mode) { - struct fanotify_info *info = fanotify_event_info(event); - int dir_fh_len = fanotify_event_dir_fh_len(event); - int fh_len = fanotify_event_object_fh_len(event); - int info_len = 0; + size_t event_len = FAN_EVENT_METADATA_LEN; + struct fanotify_info *info; + int dir_fh_len; + int fh_len; int dot_len = 0; + if (!fid_mode) + return event_len; + + info = fanotify_event_info(event); + dir_fh_len = fanotify_event_dir_fh_len(event); + fh_len = fanotify_event_object_fh_len(event); + if (dir_fh_len) { - info_len += fanotify_fid_info_len(dir_fh_len, info->name_len); + event_len += fanotify_fid_info_len(dir_fh_len, info->name_len); } else if ((fid_mode & FAN_REPORT_NAME) && (event->mask & FAN_ONDIR)) { /* * With group flag FAN_REPORT_NAME, if name was not recorded in @@ -137,9 +144,9 @@ static int fanotify_event_info_len(unsigned int fid_mode, } if (fh_len) - info_len += fanotify_fid_info_len(fh_len, dot_len); + event_len += fanotify_fid_info_len(fh_len, dot_len); - return info_len; + return event_len; } /* @@ -168,7 +175,7 @@ static void fanotify_unhash_event(struct fsnotify_group *group, static struct fanotify_event *get_one_event(struct fsnotify_group *group, size_t count) { - size_t event_size = FAN_EVENT_METADATA_LEN; + size_t event_size; struct fanotify_event *event = NULL; struct fsnotify_event *fsn_event; unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); @@ -181,8 +188,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group, goto out; event = FANOTIFY_E(fsn_event); - if (fid_mode) - event_size += fanotify_event_info_len(fid_mode, event); + event_size = fanotify_event_len(event, fid_mode); if (event_size > count) { event = ERR_PTR(-EINVAL); @@ -412,8 +418,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, pr_debug("%s: group=%p event=%p\n", __func__, group, event); - metadata.event_len = FAN_EVENT_METADATA_LEN + - fanotify_event_info_len(fid_mode, event); + metadata.event_len = fanotify_event_len(event, fid_mode); metadata.metadata_len = FAN_EVENT_METADATA_LEN; metadata.vers = FANOTIFY_METADATA_VERSION; metadata.reserved = 0; -- 2.31.0